forked from quic-go/quic-go
fix logging of application errors
This commit is contained in:
@@ -7,9 +7,10 @@ import (
|
||||
|
||||
// A QuicError consists of an error code plus a error reason
|
||||
type QuicError struct {
|
||||
ErrorCode ErrorCode
|
||||
ErrorMessage string
|
||||
isTimeout bool
|
||||
ErrorCode ErrorCode
|
||||
ErrorMessage string
|
||||
isTimeout bool
|
||||
isApplicationError bool
|
||||
}
|
||||
|
||||
var _ net.Error = &QuicError{}
|
||||
@@ -38,7 +39,21 @@ func CryptoError(tlsAlert uint8, errorMessage string) *QuicError {
|
||||
}
|
||||
}
|
||||
|
||||
func ApplicationError(errorCode ErrorCode, errorMessage string) *QuicError {
|
||||
return &QuicError{
|
||||
ErrorCode: errorCode,
|
||||
ErrorMessage: errorMessage,
|
||||
isApplicationError: true,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *QuicError) Error() string {
|
||||
if e.isApplicationError {
|
||||
if len(e.ErrorMessage) == 0 {
|
||||
return fmt.Sprintf("Application error %#x", uint64(e.ErrorCode))
|
||||
}
|
||||
return fmt.Sprintf("Application error %#x: %s", uint64(e.ErrorCode), e.ErrorMessage)
|
||||
}
|
||||
if len(e.ErrorMessage) == 0 {
|
||||
return e.ErrorCode.Error()
|
||||
}
|
||||
|
||||
@@ -26,12 +26,12 @@ var _ = Describe("QUIC Transport Errors", func() {
|
||||
})
|
||||
|
||||
Context("crypto errors", func() {
|
||||
It("has a string representation for crypto errors with a message", func() {
|
||||
It("has a string representation for errors with a message", func() {
|
||||
err := CryptoError(42, "foobar")
|
||||
Expect(err.Error()).To(Equal("CRYPTO_ERROR: foobar"))
|
||||
})
|
||||
|
||||
It("has a string representation for crypto errors without a message", func() {
|
||||
It("has a string representation for errors without a message", func() {
|
||||
err := CryptoError(42, "")
|
||||
Expect(err.Error()).To(Equal("CRYPTO_ERROR: tls: bad certificate"))
|
||||
})
|
||||
@@ -42,6 +42,18 @@ var _ = Describe("QUIC Transport Errors", func() {
|
||||
})
|
||||
})
|
||||
|
||||
Context("application errors", func() {
|
||||
It("has a string representation for errors with a message", func() {
|
||||
err := ApplicationError(0x42, "foobar")
|
||||
Expect(err.Error()).To(Equal("Application error 0x42: foobar"))
|
||||
})
|
||||
|
||||
It("has a string representation for errors without a message", func() {
|
||||
err := ApplicationError(0x42, "")
|
||||
Expect(err.Error()).To(Equal("Application error 0x42"))
|
||||
})
|
||||
})
|
||||
|
||||
Context("ErrorCode", func() {
|
||||
It("works as error", func() {
|
||||
var err error = StreamStateError
|
||||
|
||||
Reference in New Issue
Block a user