1
0
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:
toimtoimtoim
2022-11-19 22:05:53 +02:00
committed by Martti T
parent fd2b102d3e
commit be23ab67cc
2 changed files with 52 additions and 25 deletions

View File

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