errs

package
v0.0.32 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 30, 2024 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AlreadyExist = NewRestError(400, "Already exist")

AlreadyExist is a predefined error for a resource that already exists (HTTP 400).

View Source
var Internal = NewRestError(500, "Internal server error")

Internal is a predefined error for internal server errors (HTTP 500).

View Source
var Invalid = NewRestError(400, "Invalid Document")
View Source
var NotFound = NewRestError(404, "Document not found")

NotFound is a predefined error for a document not found (HTTP 404).

View Source
var Unauthorized = NewRestError(401, "Unauthorized")

Unauthorized is a predefined error for unauthorized access (HTTP 401).

Functions

This section is empty.

Types

type RestError

type RestError interface {
	Status() int
	Error() string
}

RestError is an interface that defines methods for RESTful errors.

func NewRestError

func NewRestError(status int, message string) RestError

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL