fix logging of application errors

This commit is contained in:
Marten Seemann
2019-05-30 17:06:35 +08:00
parent 0da133d7db
commit cd6047b58e
4 changed files with 64 additions and 7 deletions

View File

@@ -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()
}