mirror of
https://github.com/labstack/echo.git
synced 2025-07-03 00:56:59 +02:00
Add new method HTTPError.WithInternal
This commit is contained in:
22
echo_test.go
22
echo_test.go
@ -1206,13 +1206,22 @@ func TestHTTPError(t *testing.T) {
|
||||
|
||||
assert.Equal(t, "code=400, message=map[code:12]", err.Error())
|
||||
})
|
||||
t.Run("internal", func(t *testing.T) {
|
||||
|
||||
t.Run("internal and SetInternal", 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())
|
||||
})
|
||||
|
||||
t.Run("internal and WithInternal", func(t *testing.T) {
|
||||
err := NewHTTPError(http.StatusBadRequest, map[string]interface{}{
|
||||
"code": 12,
|
||||
})
|
||||
err = err.WithInternal(errors.New("internal error"))
|
||||
assert.Equal(t, "code=400, message=map[code:12], internal=internal error", err.Error())
|
||||
})
|
||||
}
|
||||
|
||||
func TestHTTPError_Unwrap(t *testing.T) {
|
||||
@ -1223,13 +1232,22 @@ func TestHTTPError_Unwrap(t *testing.T) {
|
||||
|
||||
assert.Nil(t, errors.Unwrap(err))
|
||||
})
|
||||
t.Run("internal", func(t *testing.T) {
|
||||
|
||||
t.Run("unwrap internal and SetInternal", func(t *testing.T) {
|
||||
err := NewHTTPError(http.StatusBadRequest, map[string]interface{}{
|
||||
"code": 12,
|
||||
})
|
||||
err.SetInternal(errors.New("internal error"))
|
||||
assert.Equal(t, "internal error", errors.Unwrap(err).Error())
|
||||
})
|
||||
|
||||
t.Run("unwrap internal and WithInternal", func(t *testing.T) {
|
||||
err := NewHTTPError(http.StatusBadRequest, map[string]interface{}{
|
||||
"code": 12,
|
||||
})
|
||||
err = err.WithInternal(errors.New("internal error"))
|
||||
assert.Equal(t, "internal error", errors.Unwrap(err).Error())
|
||||
})
|
||||
}
|
||||
|
||||
func TestDefaultHTTPErrorHandler(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user