bouncer/internal/admin/error.go
William Petit aab5452fa2
All checks were successful
Cadoles/bouncer/pipeline/head This commit looks good
feat: sentry integration
ref #3
2023-07-05 12:05:30 -06:00

40 lines
873 B
Go

package admin
import (
"context"
"fmt"
"net/http"
"forge.cadoles.com/cadoles/bouncer/internal/schema"
"github.com/getsentry/sentry-go"
"gitlab.com/wpetit/goweb/api"
"gitlab.com/wpetit/goweb/logger"
)
const ErrCodeAlreadyExist api.ErrorCode = "already-exist"
func invalidDataErrorResponse(w http.ResponseWriter, r *http.Request, err *schema.InvalidDataError) {
keyErrors := err.KeyErrors()
message := ""
for idx, err := range keyErrors {
if idx != 0 {
message += ", "
}
message += fmt.Sprintf("Path [%s]: %s", err.PropertyPath, err.Message)
}
api.ErrorResponse(w, http.StatusBadRequest, api.ErrCodeInvalidRequest, &struct {
Message string `json:"message"`
}{
Message: message,
})
return
}
func logAndCaptureError(ctx context.Context, message string, err error) {
sentry.CaptureException(err)
logger.Error(ctx, message, logger.E(err))
}