Documentation ¶
Index ¶
- Constants
- Variables
- func ErrorHandler(c *gin.Context)
- func TryParse(response *http.Response) error
- type APIError
- func BadRequest(message string, code string) *APIError
- func BadRequestField(message string, code string, field string) *APIError
- func BadRequestFields(fields map[string]FieldError) *APIError
- func Conflict(message string, code string, field string) *APIError
- func Error(status int, message string, code string) *APIError
- func Forbidden(message string, code string) *APIError
- func Internal(message string, code string) *APIError
- func InternalDefault() *APIError
- func NotFound(message string) *APIError
- func Parse(response *http.Response) *APIError
- func ParseFailed() *APIError
- func ServiceUnavailable() *APIError
- func Unauthorized() *APIError
- func Unprocessable(message string, code string) *APIError
- type Err
- type FieldError
- type Validator
Constants ¶
View Source
const ( ContentTypeV1 = "application/vnd.mysterium.error+json" ErrCodeNotFound = "not_found" ErrCodeInternal = "internal" ErrCodeParseFailed = "parse_failed" ErrCodeValidationFailed = "validation_failed" )
View Source
const ( ValidateErrRequired = "required" ValidateErrInvalidVal = "invalid_value" )
Variables ¶
View Source
var DefaultErrStatic, _ = json.Marshal(defaultErr())
Functions ¶
func ErrorHandler ¶
ErrorHandler gets the first error from request context and formats it to an error response.
Types ¶
type APIError ¶
type APIError struct { Err Err `json:"error"` Status int `json:"status"` Path string `json:"path"` }
APIError represents an error response from REST API service.
func BadRequest ¶
func BadRequestFields ¶
func BadRequestFields(fields map[string]FieldError) *APIError
func InternalDefault ¶
func InternalDefault() *APIError
func ParseFailed ¶
func ParseFailed() *APIError
func ServiceUnavailable ¶
func ServiceUnavailable() *APIError
func Unauthorized ¶
func Unauthorized() *APIError
func Unprocessable ¶
type Err ¶
type Err struct { Code string `json:"code"` Message string `json:"message"` Detail string `json:"detail,omitempty"` Fields map[string]FieldError `json:"fields,omitempty"` }
Err contains the error details.
type FieldError ¶
FieldError contains the reason why a field failed validation.
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
func NewValidator ¶
func NewValidator() *Validator
Click to show internal directories.
Click to hide internal directories.