Exemplo n.º 1
0
func renderErrorsAsHTMLFunc(next web.HTTPHandle) web.HTTPHandle {
	return func(rw http.ResponseWriter, r *http.Request, c *ctx.Context) error {
		httpErr := httperr.Convert(next(rw, r, c))
		if httpErr != nil {
			rw.WriteHeader(httpErr.Status)
			// TODO render error as html page
			c.Printf("respond with error=%s", httpErr.Error())
			if stack := httpErr.Stacktrace; stack != "" {
				c.Printf("%s", stack)
			}
		}
		return nil
	}
}
Exemplo n.º 2
0
func renderErrorsAsJSONFunc(next web.HTTPHandle) web.HTTPHandle {
	return func(rw http.ResponseWriter, r *http.Request, c *ctx.Context) error {
		httpErr := httperr.Convert(next(rw, r, c))
		if httpErr != nil {
			rw.WriteHeader(httpErr.Status)
			_ = renderJSON(rw, httpErr)
			c.Printf("error_response=%s", httpErr.Error())
			if stack := httpErr.Stacktrace; stack != "" {
				c.Printf("%s", stack)
			}
		}
		return nil
	}
}