wip
This commit is contained in:
62
mangezmieux-backend/internal/responses/error.go
Normal file
62
mangezmieux-backend/internal/responses/error.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package responses
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrBadRequestFormat = APIError{
|
||||
Type: "bad_format",
|
||||
HTTPCode: http.StatusBadRequest,
|
||||
Description: "unable to read request body, please check that the json is valid",
|
||||
}
|
||||
ErrDataValidation = APIError{
|
||||
Type: "data_validation",
|
||||
HTTPCode: http.StatusBadRequest,
|
||||
Description: "the data are not valid",
|
||||
}
|
||||
|
||||
ErrNotFound = APIError{
|
||||
Type: "not_found",
|
||||
HTTPCode: http.StatusNotFound,
|
||||
}
|
||||
|
||||
ErrAlreadyExists = APIError{
|
||||
Type: "already_exists",
|
||||
HTTPCode: http.StatusConflict,
|
||||
}
|
||||
|
||||
ErrUnauthorized = APIError{
|
||||
Type: "unauthorized",
|
||||
HTTPCode: http.StatusUnauthorized,
|
||||
}
|
||||
|
||||
ErrForbidden = APIError{
|
||||
Type: "forbidden",
|
||||
HTTPCode: http.StatusForbidden,
|
||||
}
|
||||
|
||||
ErrInternalServer = APIError{
|
||||
Type: "internal_server_error",
|
||||
HTTPCode: http.StatusInternalServerError,
|
||||
}
|
||||
)
|
||||
|
||||
type APIError struct {
|
||||
HTTPCode int `json:"-"`
|
||||
Type string `json:"error"`
|
||||
Description string `json:"errorDescription"`
|
||||
Details []FieldError `json:"errorDetails,omitempty"`
|
||||
Headers map[string][]string `json:"-"`
|
||||
}
|
||||
|
||||
type FieldError struct {
|
||||
Field string `json:"field"`
|
||||
Constraint string `json:"constraint"`
|
||||
Description string `json:"description"`
|
||||
}
|
||||
|
||||
func (e *APIError) Error() string {
|
||||
return fmt.Sprintf("error : %d, %s, %s, %v", e.HTTPCode, e.Type, e.Description, e.Details)
|
||||
}
|
||||
Reference in New Issue
Block a user