forked from quic-go/quic-go
use IETF QUIC transport error codes
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user