ErrorPage is used to return error page HTML. It also returns standard HTTP status code. @param l: if true, log error
(c *gin.Context, err error, code int, l ...bool)
| 45 | // It also returns standard HTTP status code. |
| 46 | // @param l: if true, log error |
| 47 | func ErrorPage(c *gin.Context, err error, code int, l ...bool) { |
| 48 | |
| 49 | if len(l) > 0 && l[0] { |
| 50 | if flags.Debug || flags.Dev { |
| 51 | log.Errorf("%+v", err) |
| 52 | } else { |
| 53 | log.Errorf("%v", err) |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | codes := fmt.Sprintf("%d %s", code, http.StatusText(code)) |
| 58 | |
| 59 | html := fmt.Sprintf(`<!DOCTYPE html> |
| 60 | <html lang="en"> |
| 61 | <head> |
| 62 | <meta charset="utf-8" /> |
| 63 | <meta name="viewport" content="width=device-width, initial-scale=1" /> |
| 64 | <meta name="color-scheme" content="dark light" /> |
| 65 | <meta name="robots" content="noindex" /> |
| 66 | <title>%s</title> |
| 67 | </head> |
| 68 | <body> |
| 69 | <h1>%s</h1> |
| 70 | <hr> |
| 71 | <p>%s</p> |
| 72 | </body> |
| 73 | </html>`, |
| 74 | codes, codes, html.EscapeString(hidePrivacy(err.Error()))) |
| 75 | c.Data(code, "text/html; charset=utf-8", []byte(html)) |
| 76 | c.Abort() |
| 77 | } |
| 78 | |
| 79 | func ErrorWithDataResp(c *gin.Context, err error, code int, data interface{}, l ...bool) { |
| 80 | if len(l) > 0 && l[0] { |
no test coverage detected