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