mirror of
https://github.com/cuigh/swirl
synced 2024-12-31 16:23:13 +00:00
Better error handling
This commit is contained in:
parent
4ac6aa0151
commit
0b2fdb035d
12
main.go
12
main.go
@ -42,10 +42,18 @@ func server() *web.Server {
|
|||||||
|
|
||||||
// customize error handler
|
// customize error handler
|
||||||
web.DefaultErrorHandler.OnCode(http.StatusNotFound, func(ctx web.Context, err error) {
|
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) {
|
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()
|
ws := web.Auto()
|
||||||
|
Loading…
Reference in New Issue
Block a user