2023-04-24 20:52:12 +02:00
|
|
|
package admin
|
|
|
|
|
|
|
|
import (
|
2023-07-05 20:05:30 +02:00
|
|
|
"context"
|
2023-04-24 20:52:12 +02:00
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"forge.cadoles.com/cadoles/bouncer/internal/schema"
|
|
|
|
"gitlab.com/wpetit/goweb/api"
|
2023-07-05 20:05:30 +02:00
|
|
|
"gitlab.com/wpetit/goweb/logger"
|
2023-04-24 20:52:12 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
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,
|
|
|
|
})
|
|
|
|
}
|
2023-07-05 20:05:30 +02:00
|
|
|
|
|
|
|
func logAndCaptureError(ctx context.Context, message string, err error) {
|
2024-09-27 10:15:08 +02:00
|
|
|
logger.Error(ctx, message, logger.CapturedE(err))
|
2023-07-05 20:05:30 +02:00
|
|
|
}
|