Merge pull request #692 from phuslu/nerrors

Implement Timeout()/Temproary() for QuicError
This commit is contained in:
Lucas Clemente
2017-06-21 18:26:50 +02:00
committed by GitHub
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")