From 03f78b2e4a5353173d96cbfbe19a3195cdc032f4 Mon Sep 17 00:00:00 2001 From: Chenrui <631807682@qq.com> Date: Wed, 8 Jul 2020 18:09:01 +0800 Subject: [PATCH] fix: add error code support --- error.go | 15 ++++++++++++++- hooks.go | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/error.go b/error.go index e5e9fd47..0b148974 100644 --- a/error.go +++ b/error.go @@ -28,7 +28,7 @@ import ( ) const ( - errorTypeHandler = iota + errorTypeHandler = iota errorTypeController ) @@ -359,6 +359,19 @@ func gatewayTimeout(rw http.ResponseWriter, r *http.Request) { ) } +// show 413 Payload Too Large +func payloadTooLarge(rw http.ResponseWriter, r *http.Request) { + responseError(rw, r, + 413, + "
The page you have requested is unavailable."+ + "
Perhaps you are here because:"+ + "

", + ) +} + func responseError(rw http.ResponseWriter, r *http.Request, errCode int, errContent string) { t, _ := template.New("beegoerrortemp").Parse(errtpl) data := M{ diff --git a/hooks.go b/hooks.go index b8671d35..49c42d5a 100644 --- a/hooks.go +++ b/hooks.go @@ -34,6 +34,7 @@ func registerDefaultErrorHandler() error { "504": gatewayTimeout, "417": invalidxsrf, "422": missingxsrf, + "413": payloadTooLarge, } for e, h := range m { if _, ok := ErrorMaps[e]; !ok {