mirror of
https://github.com/nais/wonderwall.git
synced 2026-05-08 09:27:12 +00:00
26 lines
693 B
Go
26 lines
693 B
Go
package errorhandler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/go-chi/httplog"
|
|
)
|
|
|
|
func respondError(w http.ResponseWriter, r *http.Request, statusCode int, cause error) {
|
|
logger := httplog.LogEntry(r.Context())
|
|
logger.Error().Stack().Err(cause).Msgf("error in route: %+v", cause)
|
|
w.WriteHeader(statusCode)
|
|
}
|
|
|
|
func InternalError(w http.ResponseWriter, r *http.Request, cause error) {
|
|
respondError(w, r, http.StatusInternalServerError, cause)
|
|
}
|
|
|
|
func BadRequest(w http.ResponseWriter, r *http.Request, cause error) {
|
|
respondError(w, r, http.StatusBadRequest, cause)
|
|
}
|
|
|
|
func Unauthorized(w http.ResponseWriter, r *http.Request, cause error) {
|
|
respondError(w, r, http.StatusUnauthorized, cause)
|
|
}
|