fix error string representation for errors without a message

This commit is contained in:
Marten Seemann
2019-03-07 09:53:13 +09:00
parent 7bd9844d38
commit ab47ba1021
2 changed files with 18 additions and 5 deletions

View File

@@ -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)
} }

View File

@@ -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() {