Improved error handling

This commit is contained in:
Eduard Urbach 2023-07-21 23:23:49 +02:00
parent 3d7bd89b39
commit d3c9ee3ac6
Signed by: eduard
GPG key ID: 49226B848C78F6C8
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"},