Documentation
¶
Index ¶
- func DecodeJSONBody(w http.ResponseWriter, r *http.Request, dst interface{}) error
- func IsShutdown(err error) bool
- func NewRequestError(err error, status int) error
- func NewShutdownError(message string) error
- func RespondError(ctx context.Context, log *zap.SugaredLogger, w http.ResponseWriter, err error)
- func RespondJSON(ctx context.Context, log *zap.SugaredLogger, w http.ResponseWriter, ...)
- func RespondText(ctx context.Context, log *zap.SugaredLogger, w http.ResponseWriter, ...)
- type Error
- type ErrorResponse
- type FieldError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeJSONBody ¶
func DecodeJSONBody(w http.ResponseWriter, r *http.Request, dst interface{}) error
DecodeJSONBody decodes a JSON body and returns client-friendly errors
func IsShutdown ¶
IsShutdown checks to see if the shutdown error is contained in the specified error value.
func NewRequestError ¶
NewRequestError wraps a provided error with an HTTP status code. This function should be used when handlers encounter expected errors.
func NewShutdownError ¶
NewShutdownError returns an error that causes the framework to signal a graceful shutdown.
func RespondError ¶
func RespondError(ctx context.Context, log *zap.SugaredLogger, w http.ResponseWriter, err error)
RespondError sends an error reponse back to the client and logs the error internally if the error is of type io.Error we send it's message back to the client. Otherwise, we return a HTTP 500 code with an opaque response to avoid leaking any information from the server.
func RespondJSON ¶
func RespondJSON(ctx context.Context, log *zap.SugaredLogger, w http.ResponseWriter, data interface{}, statusCode int)
RespondJSON converts a Go value to JSON and sends it to the client.
func RespondText ¶
func RespondText(ctx context.Context, log *zap.SugaredLogger, w http.ResponseWriter, text string, statusCode int)
RespondText returns a text response back to the client.
Types ¶
type Error ¶
type Error struct { Err error Status int Fields []FieldError }
Error is used to pass an error during the request through the application with web specific context.
type ErrorResponse ¶
type ErrorResponse struct { Error string `json:"error"` Fields []FieldError `json:"fields,omitempty"` }
ErrorResponse is the form used for API responses from failures in the API.
type FieldError ¶
FieldError is used to indicate an error with a specific request field.