Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
HTTPError Error() avoid nil pointer dereference on nil Cause
Browse files Browse the repository at this point in the history
  • Loading branch information
saurori authored and paganotoni committed Apr 19, 2022
1 parent 3241709 commit 5db1cc0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (h HTTPError) Unwrap() error {

// Error returns the cause of the error as string.
func (h HTTPError) Error() string {
return h.Cause.Error()
return fmt.Sprint(h.Cause)
}

// ErrorHandler interface for handling an error for a
Expand Down
12 changes: 12 additions & 0 deletions errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@ func Test_defaultErrorHandler_XML_production(t *testing.T) {
r.Contains(b, `</response>`)
}

func Test_defaultErrorHandler_nil_error(t *testing.T) {
r := require.New(t)
app := New(Options{})
app.GET("/", func(c Context) error {
return c.Error(http.StatusInternalServerError, nil)
})

w := httptest.New(app)
res := w.JSON("/").Get()
r.Equal(http.StatusInternalServerError, res.Code)
}

func Test_PanicHandler(t *testing.T) {
app := New(Options{})
app.GET("/string", func(c Context) error {
Expand Down

0 comments on commit 5db1cc0

Please sign in to comment.