Skip to content

Commit

Permalink
feat: disable error handler engine option (#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
rizerkrof authored Jan 12, 2025
1 parent d6300a0 commit 35d6595
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ func WithErrorHandler(errorHandler func(err error) error) func(*Engine) {
}
}

// DisableErrorHandler overrides ErrorHandler with a simple pass-through
func DisableErrorHandler() func(*Engine) {
return func(e *Engine) {
e.ErrorHandler = func(err error) error { return err }
}
}

// OutputOpenAPISpec takes the OpenAPI spec and outputs it to a JSON file
func (e *Engine) OutputOpenAPISpec() []byte {
e.OpenAPI.computeTags()
Expand Down
9 changes: 9 additions & 0 deletions engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,13 @@ func TestWithErrorHandler(t *testing.T) {
)
})
})

t.Run("disable error handler", func(t *testing.T) {
e := NewEngine(DisableErrorHandler())
err := NotFoundError{
Err: errors.New("Not Found"),
}
errResponse := e.ErrorHandler(err)
require.Equal(t, "Not Found", errResponse.Error())
})
}

0 comments on commit 35d6595

Please sign in to comment.