implement Timeout() for QuicError

This commit is contained in:
Phus Lu
2017-06-20 13:51:45 +08:00
parent 472f2b24c0
commit 13abf7800f
2 changed files with 17 additions and 0 deletions

View File

@@ -31,6 +31,16 @@ func (e *QuicError) Error() string {
return fmt.Sprintf("%s: %s", e.ErrorCode.String(), e.ErrorMessage)
}
func (e *QuicError) Timeout() bool {
switch e.ErrorCode {
case NetworkIdleTimeout,
HandshakeTimeout,
TimeoutsWithOpenStreams:
return true
}
return false
}
// ToQuicError converts an arbitrary error to a QuicError. It leaves QuicErrors
// unchanged, and properly handles `ErrorCode`s.
func ToQuicError(err error) *QuicError {

View File

@@ -22,6 +22,13 @@ var _ = Describe("Quic error", func() {
})
})
Context("TimeoutError", func() {
It("works as timeout error", func() {
err := Error(HandshakeTimeout, "handshake timeout")
Expect(err.Timeout()).Should(BeTrue())
})
})
Context("ToQuicError", func() {
It("leaves QuicError unchanged", func() {
err := Error(DecryptionFailure, "foo")