Documentation
¶
Index ¶
- Variables
- func CreatedResponse(c *gin.Context, msg string, data interface{})
- func ErrorResponse(c *gin.Context, err *Error)
- func OkResponse(c *gin.Context, msg string, data interface{})
- func ValidateErrorResponse(c *gin.Context, err error)
- type Error
- type TDataResponse
- type TErrResponse
- type TResponse
Constants ¶
This section is empty.
Variables ¶
var ( ErrBadRequest = errors.New("bad request") ErrJWTInternalError = errors.New("jwt internal error") ErrNotFound = errors.New("resource not found") ErrInternalError = errors.New("internal error") ErrInvalidToken = errors.New("invalid token") ErrExpiredToken = errors.New("expired token") ErrStolenToken = errors.New("stolen token") ErrInvalidObjectID = errors.New("invalid object id") ErrValidation = errors.New("validation error") )
Generic error represents a generic error response.
Functions ¶
func CreatedResponse ¶
CreatedResponse is a helper function that writes a JSON response to the provided gin.Context with an HTTP status of http.StatusCreated. The response includes the provided message and the provided data.
func ErrorResponse ¶
ErrorResponse writes a JSON response to the provided gin.Context with an HTTP status corresponding to the error code. The response includes the error message.
func OkResponse ¶
OkResponse is a helper function that writes a JSON response to the provided gin.Context with an HTTP status of http.StatusOK. The response includes the provided message and the provided data.
func ValidateErrorResponse ¶
ValidateErrorResponse writes a JSON response to the provided gin.Context with an HTTP status corresponding to the error code. The response includes the error message and a list of validation error messages, if any.
Types ¶
type Error ¶
type Error struct {
// contains filtered or unexported fields
}
Error represents a composite error that contains both an application-level error and a service-level error.
func NewError ¶
NewError creates a new Error instance with the given application-level and service-level errors.
func (*Error) Code ¶
Code returns the appropriate HTTP status code based on the application-level error associated with the Error.
func (*Error) Error ¶
Error returns a string representation of the composite error, which includes both the application-level error and the service-level error.
func (*Error) ServiceErr ¶
ServiceErr returns the service-level error associated with the Error.
type TDataResponse ¶
type TDataResponse struct {
TResponse
Data interface{} `json:"data"`
}
TDataResponse is a response type that includes a data field. It embeds the TResponse struct and adds a Data field to hold the response data.
type TErrResponse ¶
type TErrResponse struct {
TResponse
Errors interface{} `json:"errors"`
}
TErrResponse is a response type that includes an error field. It embeds the TResponse struct and adds an Errors field to hold any errors that occurred.