forked from quic-go/quic-go
fix error string representation for errors without a message
This commit is contained in:
@@ -31,6 +31,9 @@ func TimeoutError(errorMessage string) *QuicError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *QuicError) Error() string {
|
func (e *QuicError) Error() string {
|
||||||
|
if len(e.ErrorMessage) == 0 {
|
||||||
|
return e.ErrorCode.String()
|
||||||
|
}
|
||||||
return fmt.Sprintf("%s: %s", e.ErrorCode.String(), e.ErrorMessage)
|
return fmt.Sprintf("%s: %s", e.ErrorCode.String(), e.ErrorMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,11 +8,21 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var _ = Describe("QUIC Transport Errors", func() {
|
var _ = Describe("QUIC Transport Errors", func() {
|
||||||
Context("QuicError", func() {
|
It("has a string representation", func() {
|
||||||
It("has a string representation", func() {
|
err := Error(FlowControlError, "foobar")
|
||||||
err := Error(FlowControlError, "foobar")
|
Expect(err.Timeout()).To(BeFalse())
|
||||||
Expect(err.Error()).To(Equal("FLOW_CONTROL_ERROR: foobar"))
|
Expect(err.Error()).To(Equal("FLOW_CONTROL_ERROR: foobar"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("has a string representation for empty error phrases", func() {
|
||||||
|
err := Error(FlowControlError, "")
|
||||||
|
Expect(err.Error()).To(Equal("FLOW_CONTROL_ERROR"))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("has a string representation for timeout errors", func() {
|
||||||
|
err := TimeoutError("foobar")
|
||||||
|
Expect(err.Timeout()).To(BeTrue())
|
||||||
|
Expect(err.Error()).To(Equal("NO_ERROR: foobar"))
|
||||||
})
|
})
|
||||||
|
|
||||||
Context("ErrorCode", func() {
|
Context("ErrorCode", func() {
|
||||||
|
|||||||
Reference in New Issue
Block a user