Documentation
¶
Index ¶
- func HandleKnownBusinessValidationErrors(err error) error
- func ValidateBadRequestFieldsError(requiredFields, knownInvalidFields map[string]string, entityType string, ...) error
- func ValidateBusinessError(err error, entityType string, args ...any) error
- func ValidateInternalError(err error, entityType string) error
- func ValidateUnmarshallingError(err error) error
- type EntityConflictError
- type EntityNotFoundError
- type FailedPreconditionError
- type FieldValidations
- type ForbiddenError
- type HTTPError
- type InternalServerError
- type ResponseError
- type UnauthorizedError
- type UnknownFields
- type UnprocessableOperationError
- type ValidationError
- type ValidationKnownFieldsError
- type ValidationUnknownFieldsError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HandleKnownBusinessValidationErrors ¶ added in v3.2.0
func ValidateBadRequestFieldsError ¶
func ValidateBadRequestFieldsError(requiredFields, knownInvalidFields map[string]string, entityType string, unknownFields map[string]any) error
ValidateBadRequestFieldsError validates the error and returns the appropriate bad request error code, title, message, and the invalid fields.
Parameters: - requiredFields: A map of missing required fields and their error messages. - knownInvalidFields: A map of known invalid fields and their validation errors. - entityType: The type of the entity associated with the error. - unknownFields: A map of unknown fields and their error messages.
Returns: - An error indicating the validation result, which could be a ValidationUnknownFieldsError or a ValidationKnownFieldsError.
func ValidateBusinessError ¶
ValidateBusinessError validates the error and returns the appropriate business error code, title, and message.
Parameters:
- err: The error to be validated (ref: https://github.com/LerianStudio/midaz/v3/common/constant/errors.go).
- entityType: The type of the entity related to the error.
- args: Additional arguments for formatting error messages.
Returns:
- error: The appropriate business error with code, title, and message.
func ValidateInternalError ¶
ValidateInternalError validates the error and returns an appropriate InternalServerError.
Parameters: - err: The error to be validated. - entityType: The type of the entity associated with the error.
Returns: - An InternalServerError with the appropriate code, title, message.
func ValidateUnmarshallingError ¶
ValidateUnmarshallingError validates the error and returns an appropriate ResponseError.
Types ¶
type EntityConflictError ¶
type EntityConflictError struct {
EntityType string `json:"entityType,omitempty"`
Title string `json:"title,omitempty"`
Message string `json:"message,omitempty"`
Code string `json:"code,omitempty"`
Err error `json:"err,omitempty"`
}
EntityConflictError records an error indicating an entity already exists in some repository You can use it to represent a Database conflict, cache or any other repository.
func (EntityConflictError) Error ¶
func (e EntityConflictError) Error() string
Error implements the error interface.
func (EntityConflictError) Unwrap ¶
func (e EntityConflictError) Unwrap() error
Unwrap implements the error interface introduced in Go 1.13 to unwrap the internal error.
type EntityNotFoundError ¶
type EntityNotFoundError struct {
EntityType string `json:"entityType,omitempty"`
Title string `json:"title,omitempty"`
Message string `json:"message,omitempty"`
Code string `json:"code,omitempty"`
Err error `json:"err,omitempty"`
}
EntityNotFoundError records an error indicating an entity was not found in any case that caused it. You can use it to represent a Database not found, cache not found or any other repository.
func (EntityNotFoundError) Error ¶
func (e EntityNotFoundError) Error() string
Error implements the error interface.
func (EntityNotFoundError) Unwrap ¶
func (e EntityNotFoundError) Unwrap() error
Unwrap implements the error interface introduced in Go 1.13 to unwrap the internal error.
type FailedPreconditionError ¶
type FailedPreconditionError struct {
EntityType string `json:"entityType,omitempty"`
Title string `json:"title,omitempty"`
Message string `json:"message,omitempty"`
Code string `json:"code,omitempty"`
Err error `json:"err,omitempty"`
}
FailedPreconditionError indicates a precondition failed during an operation.
func (FailedPreconditionError) Error ¶
func (e FailedPreconditionError) Error() string
type FieldValidations ¶
FieldValidations is a map of known fields and their validation errors.
type ForbiddenError ¶
type ForbiddenError struct {
EntityType string `json:"entityType,omitempty"`
Title string `json:"title,omitempty"`
Message string `json:"message,omitempty"`
Code string `json:"code,omitempty"`
Err error `json:"err,omitempty"`
}
ForbiddenError indicates an operation that couldn't be performed because the authenticated user has no sufficient privileges.
func (ForbiddenError) Error ¶
func (e ForbiddenError) Error() string
type HTTPError ¶
type HTTPError struct {
EntityType string `json:"entityType,omitempty"`
Title string `json:"title,omitempty"`
Message string `json:"message,omitempty"`
Code string `json:"code,omitempty"`
Err error `json:"err,omitempty"`
}
HTTPError indicates an http error raised in an http client.
type InternalServerError ¶
type InternalServerError struct {
EntityType string `json:"entityType,omitempty"`
Title string `json:"title,omitempty"`
Message string `json:"message,omitempty"`
Code string `json:"code,omitempty"`
Err error `json:"err,omitempty"`
}
InternalServerError indicates midaz has an unexpected failure during an operation.
func (InternalServerError) Error ¶
func (e InternalServerError) Error() string
type ResponseError ¶
type ResponseError struct {
EntityType string `json:"entityType,omitempty"`
Title string `json:"title,omitempty"`
Message string `json:"message,omitempty"`
Code string `json:"code,omitempty"`
Err error `json:"err,omitempty"`
}
ResponseError is a struct used to return errors to the client.
func (ResponseError) Error ¶
func (r ResponseError) Error() string
Error returns the message of the ResponseError.
No parameters. Returns a string.
type UnauthorizedError ¶
type UnauthorizedError struct {
}
UnauthorizedError indicates an operation that couldn't be performed because there's no user authenticated.
func (UnauthorizedError) Error ¶
func (e UnauthorizedError) Error() string
type UnknownFields ¶
UnknownFields is a map of unknown fields and their error messages.
type UnprocessableOperationError ¶
type UnprocessableOperationError struct {
EntityType string `json:"entityType,omitempty"`
Title string `json:"title,omitempty"`
Message string `json:"message,omitempty"`
Code string `json:"code,omitempty"`
Err error `json:"err,omitempty"`
}
UnprocessableOperationError indicates an operation that couldn't be performed because it's invalid.
func (UnprocessableOperationError) Error ¶
func (e UnprocessableOperationError) Error() string
type ValidationError ¶
type ValidationError struct {
EntityType string `json:"entityType,omitempty"`
Title string `json:"title,omitempty"`
Message string `json:"message,omitempty"`
Code string `json:"code,omitempty"`
Err error `json:"err,omitempty"`
}
ValidationError records an error indicating some validation have failed in any case that caused it. You can use it to represent a validation error or any other repository.
func (ValidationError) Error ¶
func (e ValidationError) Error() string
Error implements the error interface.
func (ValidationError) Unwrap ¶
func (e ValidationError) Unwrap() error
Unwrap implements the error interface introduced in Go 1.13 to unwrap the internal error.
type ValidationKnownFieldsError ¶
type ValidationKnownFieldsError struct {
EntityType string `json:"entityType,omitempty"`
Title string `json:"title,omitempty"`
Message string `json:"message,omitempty"`
Code string `json:"code,omitempty"`
Err error `json:"err,omitempty"`
Fields FieldValidations `json:"fields,omitempty"`
}
ValidationKnownFieldsError records an error that occurred during a validation of known fields.
func (ValidationKnownFieldsError) Error ¶
func (r ValidationKnownFieldsError) Error() string
Error returns the error message for a ValidationKnownFieldsError.
No parameters. Returns a string.
type ValidationUnknownFieldsError ¶
type ValidationUnknownFieldsError struct {
EntityType string `json:"entityType,omitempty"`
Title string `json:"title,omitempty"`
Message string `json:"message,omitempty"`
Code string `json:"code,omitempty"`
Err error `json:"err,omitempty"`
Fields UnknownFields `json:"fields,omitempty"`
}
ValidationUnknownFieldsError records an error that occurred during a validation of unknown fields.
func (ValidationUnknownFieldsError) Error ¶
func (r ValidationUnknownFieldsError) Error() string
Error returns the error message for a ValidationUnknownFieldsError.
No parameters. Returns a string.