errors/http.go
func ToHTTP(in error, w http.ResponseWriter) error {
	w.Header().Set("Content-Type", "application/json")
	if err, ok := in.(Error); ok {
		w.Header().Set(CodeHeader, err.Code().String())
		w.WriteHeader(err.Type().HTTPStatusCode())
		return json.NewEncoder(w).Encode(toJSON(err))
	}

	w.WriteHeader(http.StatusInternalServerError)
	return json.NewEncoder(w).Encode(&jsonError{
		Message: in.Error(),
		Type:    Unknown,
	})
}
func ToHTTP(in error, w http.ResponseWriter) error {
	w.Header().Set("Content-Type", "application/json")
	if err, ok := in.(Error); ok {
		w.Header().Set(CodeHeader, err.Code().String())
		w.WriteHeader(err.Type().HTTPStatusCode())
		return json.NewEncoder(w).Encode(toJSON(err))
	}

	w.WriteHeader(http.StatusInternalServerError)
	return json.NewEncoder(w).Encode(&jsonError{
		Message: in.Error(),
		Type:    Unknown,
	})
}
// ToHTTP writes the error to the http response