File tree Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Expand file tree Collapse file tree 1 file changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -55,12 +55,18 @@ func midRecover(next echo.HandlerFunc) echo.HandlerFunc {
5555// HTTPErrorHandler 全局错误捕捉
5656func HTTPErrorHandler (err error , ctx echo.Context ) {
5757 if ! ctx .Response ().Committed {
58- if strings .Contains (err .Error (), "404" ) {
59- // ctx.NoContent(404)
60- ctx .HTML (404 , html404 )
61- // ctx.Redirect(302, "/404.html")
58+ if he , ok := err .(* echo.HTTPError ); ok {
59+ if he .Code == 404 {
60+ if strings .HasPrefix (ctx .Request ().URL .Path , "/static" ) || strings .HasPrefix (ctx .Request ().URL .Path , "/dist" ) {
61+ ctx .NoContent (404 )
62+ } else {
63+ ctx .HTML (404 , html404 )
64+ }
65+ } else {
66+ ctx .JSON (utils .NewErrSvr ("系统错误" , he .Message ))
67+ }
6268 } else {
63- ctx .JSON (utils .ErrSvr (err .Error ()))
69+ ctx .JSON (utils .NewErrSvr (err .Error ()))
6470 }
6571 }
6672}
You can’t perform that action at this time.
0 commit comments