Skip to content

Commit

Permalink
Publish error function to reuse it in middlewares.
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestoalejo committed Mar 24, 2024
1 parent 47e0cd7 commit dbbdc1c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func Handler(handler HandlerError) http.Handler {

if err := handler(w, r); err != nil {
if errors.Is(ctx.Err(), context.Canceled) {
emitError(w, r, http.StatusRequestTimeout)
Error(w, http.StatusRequestTimeout)
return
}

Expand All @@ -38,7 +38,7 @@ func Handler(handler HandlerError) http.Handler {
telemetry.ReportError(r.Context(), err)

if errors.Is(ctx.Err(), context.DeadlineExceeded) {
emitError(w, r, http.StatusGatewayTimeout)
Error(w, http.StatusGatewayTimeout)
return
}

Expand All @@ -48,12 +48,12 @@ func Handler(handler HandlerError) http.Handler {
return
}

emitError(w, r, http.StatusInternalServerError)
Error(w, http.StatusInternalServerError)
}
})
}

func emitError(w http.ResponseWriter, r *http.Request, status int) {
func Error(w http.ResponseWriter, status int) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(status)

Expand Down

0 comments on commit dbbdc1c

Please sign in to comment.