func (srv *Server) HandleErrors(handle ErrorHandler) httprouter.Handle {
	return func(w http.ResponseWriter, req *http.Request, p httprouter.Params) {
		w1 := responseWriter{
			ResponseWriter: w,
		}
		ctx := req.Context()
		if err := handle(Params{
			Response: &w1,
			Request:  req,
			PathVar:  p,
			Context:  ctx,
		}); err != nil {
			if w1.headerWritten {
				// The header has already been written,
				// so we can't set the appropriate error
				// response code and there's a danger
				// that we may be corrupting the
				// response by appending a JSON error
				// message to it.
				// TODO log an error in this case.
				return
			}
			srv.WriteError(ctx, w, err)
		}
	}
}
// HandleErrors returns a handler that passes any non-nil error returned
// by handle through the error mapper and writes it as a JSON response.
//
// Note that the Params argument passed to handle will not
// have its PathPattern set as that information is not available.
HandleErrors returns a handler that passes any non-nil error returned
by handle through the error mapper and writes it as a JSON response.

Note that the Params argument passed to handle will not
have its PathPattern set as that information is not available.
// HandleErrors returns a handler that passes any non - nil error returned // by handle through the error mapper and writes it as a JSON response . // // Note that the Params argument passed to handle will not // have its PathPattern set as that information is not available .
func (srv *Server) HandleErrors(handle ErrorHandler) httprouter.Handle {
	return func(w http.ResponseWriter, req *http.Request, p httprouter.Params) {
		w1 := responseWriter{
			ResponseWriter: w,
		}
		ctx := req.Context()
		if err := handle(Params{
			Response: &w1,
			Request:  req,
			PathVar:  p,
			Context:  ctx,
		}); err != nil {
			if w1.headerWritten {
				return
			}
			srv.WriteError(ctx, w, err)
		}
	}
}
func ( srv * Server ) HandleErrors ( handle ErrorHandler ) httprouter . Handle { return func ( w http . ResponseWriter , req * http . Request , p httprouter . Params ) { w1 := responseWriter { ResponseWriter : w , } ctx := req . Context ( ) if err := handle ( Params { Response : & w1 , Request : req , PathVar : p , Context : ctx , } ) ; err != nil { if w1 . headerWritten { return } srv . WriteError ( ctx , w , err ) } } }
HandleErrors returns a handler that passes any non-nil error returned
by handle through the error mapper and writes it as a JSON response.
HandleErrors returns a handler that passes any non - nil error returned by handle through the error mapper and writes it as a JSON response .
// The header has already been written, // so we can't set the appropriate error // response code and there's a danger // that we may be corrupting the // response by appending a JSON error // message to it. // TODO log an error in this case.