mirror of
https://github.com/nais/wonderwall.git
synced 2026-05-21 07:42:53 +00:00
feat: use latest go-chi v5, add middlewares for panic recovery and logging
Co-Authored-By: Sindre Rødseth Hansen <sindre.rodseth.hansen@nav.no>
This commit is contained in:
@@ -1,22 +1,14 @@
|
||||
package errorhandler
|
||||
|
||||
import (
|
||||
"github.com/nais/wonderwall/pkg/middleware"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"net/http"
|
||||
|
||||
"github.com/go-chi/httplog"
|
||||
)
|
||||
|
||||
func respondError(w http.ResponseWriter, r *http.Request, statusCode int, cause error) {
|
||||
id, ok := middleware.GetCorrelationID(r.Context())
|
||||
if !ok {
|
||||
log.Warnf("no correlation id in context")
|
||||
}
|
||||
|
||||
logFields := log.Fields{
|
||||
"correlation_id": id,
|
||||
}
|
||||
|
||||
log.WithFields(logFields).Error(cause)
|
||||
logger := httplog.LogEntry(r.Context())
|
||||
logger.Error().Stack().Err(cause).Msgf("error in route: %+v", cause)
|
||||
w.WriteHeader(statusCode)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user