diff --git a/engine.go b/engine.go index ce0c47fe..cd75ef0b 100644 --- a/engine.go +++ b/engine.go @@ -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() diff --git a/engine_test.go b/engine_test.go index 3962716f..def181c6 100644 --- a/engine_test.go +++ b/engine_test.go @@ -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()) + }) }