forked from quic-go/quic-go
add error code string representation to QuicError.Error
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package protocol
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/lucas-clemente/quic-go/errorcodes"
|
||||
)
|
||||
|
||||
@@ -19,7 +21,7 @@ func Error(errorCode errorcodes.ErrorCode, errorMessage string) *QuicError {
|
||||
}
|
||||
|
||||
func (e *QuicError) Error() string {
|
||||
return e.ErrorMessage
|
||||
return fmt.Sprintf("%s: %s", e.ErrorCode.String(), e.ErrorMessage)
|
||||
}
|
||||
|
||||
var _ error = &QuicError{}
|
||||
|
||||
16
protocol/quic_error_test.go
Normal file
16
protocol/quic_error_test.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package protocol_test
|
||||
|
||||
import (
|
||||
"github.com/lucas-clemente/quic-go/errorcodes"
|
||||
"github.com/lucas-clemente/quic-go/protocol"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("Quic error", func() {
|
||||
It("has a string representation", func() {
|
||||
err := protocol.Error(errorcodes.InternalError, "foobar")
|
||||
Expect(err.Error()).To(Equal("InternalError: foobar"))
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user