use IETF QUIC transport error codes

This commit is contained in:
Marten Seemann
2019-03-06 13:19:21 +09:00
parent 966b00dd3d
commit 9c09e84765
34 changed files with 156 additions and 333 deletions

View File

@@ -16,6 +16,7 @@ func (e ErrorCode) Error() string {
type QuicError struct {
ErrorCode ErrorCode
ErrorMessage string
isTimeout bool
}
var _ net.Error = &QuicError{}
@@ -28,6 +29,14 @@ func Error(errorCode ErrorCode, errorMessage string) *QuicError {
}
}
// TimeoutError creates a new QuicError instance for a timeout error
func TimeoutError(errorMessage string) *QuicError {
return &QuicError{
ErrorMessage: errorMessage,
isTimeout: true,
}
}
func (e *QuicError) Error() string {
return fmt.Sprintf("%s: %s", e.ErrorCode.String(), e.ErrorMessage)
}
@@ -39,13 +48,7 @@ func (e *QuicError) Temporary() bool {
// Timeout says if this error is a timeout.
func (e *QuicError) Timeout() bool {
switch e.ErrorCode {
case NetworkIdleTimeout,
HandshakeTimeout,
TimeoutsWithOpenStreams:
return true
}
return false
return e.isTimeout
}
// ToQuicError converts an arbitrary error to a QuicError. It leaves QuicErrors