io

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

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

func IsShutdown(err error) bool

IsShutdown checks to see if the shutdown error is contained in the specified error value.

func NewRequestError

func NewRequestError(err error, status int) error

NewRequestError wraps a provided error with an HTTP status code. This function should be used when handlers encounter expected errors.

func NewShutdownError

func NewShutdownError(message string) error

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.

func (*Error) Error

func (err *Error) Error() string

Error implements the error interface. It uses the default message of the wrapped error. This is what will be shown in the services' logs.

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

type FieldError struct {
	Field string `json:"field"`
	Error string `json:"error"`
}

FieldError is used to indicate an error with a specific request field.

Jump to

Keyboard shortcuts

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