Пример #1
0
func (h handler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	p, contentType, err := FromRequest(h.Registry, req.URL.Path, req.URL.Query())
	if err != nil {
		http.Error(w, errhttp.GetErrorBody(err), errhttp.GetStatusCode(err, 500))
		return
	}
	w.Header().Set("Content-Type", contentType)
	p(w)
}
Пример #2
0
func (b Base) handleError(w ResponseWriter, r *http.Request, err error) {
	if err == nil {
		return
	}
	if w.WroteHeader() {
		logger.Errore(err)
		return
	}
	if b.ErrHandler != nil {
		b.ErrHandler(w, r, err)
		return
	}
	http.Error(w, errhttp.GetErrorBody(err),
		errhttp.GetStatusCode(err, http.StatusInternalServerError))
}