Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var AlreadyExist = NewRestError(400, "Already exist")
AlreadyExist is a predefined error for a resource that already exists (HTTP 400).
var Internal = NewRestError(500, "Internal server error")
Internal is a predefined error for internal server errors (HTTP 500).
var Invalid = NewRestError(400, "Invalid Document")
var NotFound = NewRestError(404, "Document not found")
NotFound is a predefined error for a document not found (HTTP 404).
Unauthorized is a predefined error for unauthorized access (HTTP 401).
Functions ¶
This section is empty.
Types ¶
type RestError ¶
RestError is an interface that defines methods for RESTful errors.
func NewRestError ¶
NewRestError creates a new RestError with the given status code and message.
type Validation ¶
type Validation interface { Add(path string, message string) Validation Error() string }
Validation represents an interface for handling validation errors. It provides methods to add validation errors and retrieve the error message.
Add adds a validation error with the specified path and message. It returns the updated Validation instance.
Error returns a string representation of the validation errors.
func NewValidation ¶
func NewValidation() Validation
NewValidation creates a new instance of ValidationErr with an empty list of error messages. It returns the Validation interface implemented by ValidationErr.
type ValidationErr ¶
type ValidationErr struct {
Messages []errField `json:"messages"`
}
ValidationErr represents a validation error that contains a list of error messages.
func (*ValidationErr) Add ¶
func (e *ValidationErr) Add(path string, message string) Validation
Add appends a new validation error message to the ValidationErr instance. It takes a path and a message as parameters, creates an errField with these values, and adds it to the Messages slice of the ValidationErr instance. It returns the updated ValidationErr instance.
Parameters:
- path: The path or field name where the validation error occurred.
- message: The validation error message.
Returns:
- Validation: The updated ValidationErr instance with the new error message added.
func (*ValidationErr) Error ¶
func (e *ValidationErr) Error() string
Error implements the error interface for ValidationErr.