func (srv *Server) WriteError(ctx context.Context, w http.ResponseWriter, err error) {
	if srv.ErrorWriter != nil {
		srv.ErrorWriter(ctx, w, err)
		return
	}
	errorMapper := srv.ErrorMapper
	if errorMapper == nil {
		errorMapper = DefaultErrorMapper
	}
	status, resp := errorMapper(ctx, err)
	err1 := WriteJSON(w, status, resp)
	if err1 == nil {
		return
	}
	// TODO log an error ?

	// JSON-marshaling the original error failed, so try to send that
	// error instead; if that fails, give up and go home.
	status1, resp1 := errorMapper(ctx, errgo.Notef(err1, "cannot marshal error response %q", err))
	err2 := WriteJSON(w, status1, resp1)
	if err2 == nil {
		return
	}

	w.WriteHeader(http.StatusInternalServerError)
	w.Write([]byte(fmt.Sprintf("really cannot marshal error response %q: %v", err, err1)))
}
// WriteError writes an error to a ResponseWriter and sets the HTTP
// status code, using srv.ErrorMapper to determine the actually written
// response.
//
// It uses WriteJSON to write the error body returned from the
// ErrorMapper so it is possible to add custom headers to the HTTP error
// response by implementing HeaderSetter.
WriteError writes an error to a ResponseWriter and sets the HTTP
status code, using srv.ErrorMapper to determine the actually written
response.

It uses WriteJSON to write the error body returned from the
ErrorMapper so it is possible to add custom headers to the HTTP error
response by implementing HeaderSetter.
// WriteError writes an error to a ResponseWriter and sets the HTTP // status code using srv . ErrorMapper to determine the actually written // response . // // It uses WriteJSON to write the error body returned from the // ErrorMapper so it is possible to add custom headers to the HTTP error // response by implementing HeaderSetter .
func (srv *Server) WriteError(ctx context.Context, w http.ResponseWriter, err error) {
	if srv.ErrorWriter != nil {
		srv.ErrorWriter(ctx, w, err)
		return
	}
	errorMapper := srv.ErrorMapper
	if errorMapper == nil {
		errorMapper = DefaultErrorMapper
	}
	status, resp := errorMapper(ctx, err)
	err1 := WriteJSON(w, status, resp)
	if err1 == nil {
		return
	}
	status1, resp1 := errorMapper(ctx, errgo.Notef(err1, "cannot marshal error response %q", err))
	err2 := WriteJSON(w, status1, resp1)
	if err2 == nil {
		return
	}
	w.WriteHeader(http.StatusInternalServerError)
	w.Write([]byte(fmt.Sprintf("really cannot marshal error response %q: %v", err, err1)))
}
func ( srv * Server ) WriteError ( ctx context . Context , w http . ResponseWriter , err error ) { if srv . ErrorWriter != nil { srv . ErrorWriter ( ctx , w , err ) return } errorMapper := srv . ErrorMapper if errorMapper == nil { errorMapper = DefaultErrorMapper } status , resp := errorMapper ( ctx , err ) err1 := WriteJSON ( w , status , resp ) if err1 == nil { return } status1 , resp1 := errorMapper ( ctx , errgo . Notef ( err1 , " " , err ) ) err2 := WriteJSON ( w , status1 , resp1 ) if err2 == nil { return } w . WriteHeader ( http . StatusInternalServerError ) w . Write ( [ ] byte ( fmt . Sprintf ( " " , err , err1 ) ) ) }
WriteError writes an error to a ResponseWriter and sets the HTTP
status code, using srv.ErrorMapper to determine the actually written
response.
WriteError writes an error to a ResponseWriter and sets the HTTP status code using srv . ErrorMapper to determine the actually written response .
// TODO log an error ? // JSON-marshaling the original error failed, so try to send that // error instead; if that fails, give up and go home.