Improved error handling

This commit is contained in:
2023-07-21 23:23:49 +02:00
parent 7da8fffb90
commit 72ad02a2e2
3 changed files with 33 additions and 8 deletions

View File

@ -24,7 +24,11 @@ func TestRouter(t *testing.T) {
})
s.Get("/error", func(ctx server.Context) error {
return ctx.Error(http.StatusUnauthorized, errors.New("Not logged in"))
return ctx.Error(http.StatusUnauthorized, "Not logged in")
})
s.Get("/error2", func(ctx server.Context) error {
return ctx.Error(http.StatusUnauthorized, "Not logged in", errors.New("Missing auth token"))
})
s.Get("/reader", func(ctx server.Context) error {
@ -43,6 +47,7 @@ func TestRouter(t *testing.T) {
{URL: "/", Status: http.StatusOK, Body: "Hello"},
{URL: "/blog/post", Status: http.StatusOK, Body: "Hello"},
{URL: "/error", Status: http.StatusUnauthorized, Body: "Not logged in"},
{URL: "/error2", Status: http.StatusUnauthorized, Body: "Not logged in\nMissing auth token"},
{URL: "/not-found", Status: http.StatusNotFound, Body: http.StatusText(http.StatusNotFound)},
{URL: "/reader", Status: http.StatusOK, Body: "Hello"},
{URL: "/string", Status: http.StatusOK, Body: "Hello"},