Documentation
¶
Index ¶
- func NewError(err error, statusCode int) error
- func NewErrorFromMessage(message string, statusCode int) error
- func NewErrorFromStatusCode(statusCode int) error
- func NewErrorWithFields(err error, statusCode int, fields []FieldError) error
- func Respond(w http.ResponseWriter, val any, statusCode int)
- func Respond500(w http.ResponseWriter)
- func RespondError(w http.ResponseWriter, respErr error)
- type Error
- type ErrorResponse
- type FieldError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewErrorFromMessage ¶
NewErrorFromMessage creates error with status code from message
func NewErrorFromStatusCode ¶
NewErrorFromStatusCode creates error from status code
func NewErrorWithFields ¶
func NewErrorWithFields(err error, statusCode int, fields []FieldError) error
NewErrorWithFields creates error with status code and error fields
func Respond ¶
func Respond(w http.ResponseWriter, val any, statusCode int)
Respond marshals a value to JSON and writes it to response
func Respond500 ¶
func Respond500(w http.ResponseWriter)
Respond500 returns InternalServerError to client
func RespondError ¶
func RespondError(w http.ResponseWriter, respErr error)
RespondError handles outgoing errors by marshaling an error response. if error is not of type Error, then err is ignored. if no err is provided, InternalServerError returns to client
Types ¶
type Error ¶
type Error struct {
Err error
StatusCode int
Fields []FieldError
}
Error contains information about web error
type ErrorResponse ¶
type ErrorResponse struct {
Error string `json:"error"`
Fields []FieldError `json:"fields,omitempty"`
}
ErrorResponse represents response in case of a web error
type FieldError ¶
FieldError represents error in a struct field
Click to show internal directories.
Click to hide internal directories.