-
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BREAKING: WithErrorHandler server option to engine option
- Loading branch information
Showing
3 changed files
with
51 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package fuego | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestWithErrorHandler(t *testing.T) { | ||
t.Run("default engine", func(t *testing.T) { | ||
e := NewEngine() | ||
err := NotFoundError{ | ||
Err: errors.New("Not Found :c"), | ||
} | ||
errResponse := e.ErrorHandler(err) | ||
require.ErrorAs(t, errResponse, &HTTPError{}) | ||
}) | ||
t.Run("custom handler", func(t *testing.T) { | ||
e := NewEngine( | ||
WithErrorHandler(func(err error) error { | ||
return fmt.Errorf("%w foobar", err) | ||
}), | ||
) | ||
err := NotFoundError{ | ||
Err: errors.New("Not Found :c"), | ||
} | ||
errResponse := e.ErrorHandler(err) | ||
require.ErrorAs(t, errResponse, &HTTPError{}) | ||
require.ErrorContains(t, errResponse, "Not Found :c foobar") | ||
}) | ||
t.Run("should be fatal", func(t *testing.T) { | ||
require.Panics(t, func() { | ||
NewEngine( | ||
WithErrorHandler(nil), | ||
) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters