From 0b2fdb035d2bb0b0804115b780a59ae2985c3c0f Mon Sep 17 00:00:00 2001 From: cuigh Date: Mon, 20 Nov 2017 11:32:51 +0800 Subject: [PATCH] Better error handling --- main.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 92c320f..3a82caf 100644 --- a/main.go +++ b/main.go @@ -42,10 +42,18 @@ func server() *web.Server { // customize error handler web.DefaultErrorHandler.OnCode(http.StatusNotFound, func(ctx web.Context, err error) { - ctx.Redirect("/404") + if ctx.IsAJAX() { + ctx.Status(http.StatusNotFound).HTML(http.StatusText(http.StatusNotFound)) + } else { + ctx.Render("404", nil) + } }) web.DefaultErrorHandler.OnCode(http.StatusForbidden, func(ctx web.Context, err error) { - ctx.Redirect("/403") + if ctx.IsAJAX() { + ctx.Status(http.StatusForbidden).HTML("You do not have permission to perform this operation") + } else { + ctx.Render("403", nil) + } }) ws := web.Auto()