mirror of
https://github.com/labstack/echo.git
synced 2025-02-03 13:11:39 +02:00
Omit internal=<nil>
in error strings (#1525)
This commit is contained in:
parent
3e8a797db0
commit
fc4b1c0a83
3
echo.go
3
echo.go
@ -783,6 +783,9 @@ func NewHTTPError(code int, message ...interface{}) *HTTPError {
|
||||
|
||||
// Error makes it compatible with `error` interface.
|
||||
func (he *HTTPError) Error() string {
|
||||
if he.Internal == nil {
|
||||
return fmt.Sprintf("code=%d, message=%v", he.Code, he.Message)
|
||||
}
|
||||
return fmt.Sprintf("code=%d, message=%v, internal=%v", he.Code, he.Message, he.Internal)
|
||||
}
|
||||
|
||||
|
17
echo_test.go
17
echo_test.go
@ -543,10 +543,21 @@ func request(method, path string, e *Echo) (int, string) {
|
||||
}
|
||||
|
||||
func TestHTTPError(t *testing.T) {
|
||||
err := NewHTTPError(http.StatusBadRequest, map[string]interface{}{
|
||||
"code": 12,
|
||||
t.Run("non-internal", func(t *testing.T) {
|
||||
err := NewHTTPError(http.StatusBadRequest, map[string]interface{}{
|
||||
"code": 12,
|
||||
})
|
||||
|
||||
assert.Equal(t, "code=400, message=map[code:12]", err.Error())
|
||||
|
||||
})
|
||||
t.Run("internal", func(t *testing.T) {
|
||||
err := NewHTTPError(http.StatusBadRequest, map[string]interface{}{
|
||||
"code": 12,
|
||||
})
|
||||
err.SetInternal(errors.New("internal error"))
|
||||
assert.Equal(t, "code=400, message=map[code:12], internal=internal error", err.Error())
|
||||
})
|
||||
assert.Equal(t, "code=400, message=map[code:12], internal=<nil>", err.Error())
|
||||
}
|
||||
|
||||
func TestEchoClose(t *testing.T) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user