jsonapi

package
v0.0.0-...-5b6bd79 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2019 License: Apache-2.0 Imports: 12 Imported by: 4

Documentation

Index

Constants

View Source
const (
	ErrorCodeNotFound          = "not_found"
	ErrorCodeBadParameter      = "bad_parameter"
	ErrorCodeVersionConflict   = "version_conflict"
	ErrorCodeUnknownError      = "unknown_error"
	ErrorCodeConversionError   = "conversion_error"
	ErrorCodeInternalError     = "internal_error"
	ErrorCodeUnauthorizedError = "unauthorized_error"
	ErrorCodeForbiddenError    = "forbidden_error"
	ErrorCodeJWTSecurityError  = "jwt_security_error"
	ErrorCodeDataConflict      = "data_conflict_error"
)
View Source
const (
	// Media type for errors returned by the JSON API error handler middleware
	ErrorMediaIdentifier = "application/vnd.api+json"
)

Variables

This section is empty.

Functions

func ErrorHandler

func ErrorHandler(service *goa.Service, verbose bool) goa.Middleware

ErrorHandler turns a Go error into an JSONAPI HTTP response. It should be placed in the middleware chain below the logger middleware so the logger properly logs the HTTP response. ErrorHandler understands instances of goa.ServiceError and returns the status and response body embodied in them, it turns other Go error types into a 500 internal error response. If verbose is false the details of internal errors is not included in HTTP responses. If you use github.com/pkg/errors then wrapping the error will allow a trace to be printed to the logs

func ErrorToJSONAPIError

func ErrorToJSONAPIError(ctx context.Context, err error) (app.JSONAPIError, int)

ErrorToJSONAPIError returns the JSONAPI representation of an error and the HTTP status code that will be associated with it. This function knows about the models package and the errors from there as well as goa error classes.

func ErrorToJSONAPIErrors

func ErrorToJSONAPIErrors(ctx context.Context, err error) (*app.JSONAPIErrors, int)

ErrorToJSONAPIErrors is a convenience function if you just want to return one error from the models package as a JSONAPI errors array.

func JSONErrorResponse

func JSONErrorResponse(obj interface{}, err error) error

JSONErrorResponse auto maps the provided error to the correct response type If all else fails, InternalServerError is returned

Types

type BadRequest

type BadRequest interface {
	BadRequest(*app.JSONAPIErrors) error
}

BadRequest represent a Context that can return a BadRequest HTTP status

type Conflict

type Conflict interface {
	Conflict(*app.JSONAPIErrors) error
}

Conflict represent a Context that can return a Conflict HTTP status

type Forbidden

type Forbidden interface {
	Forbidden(*app.JSONAPIErrors) error
}

Forbidden represent a Context that can return a Unauthorized HTTP status

type InternalServerError

type InternalServerError interface {
	InternalServerError(*app.JSONAPIErrors) error
}

InternalServerError represent a Context that can return a InternalServerError HTTP status

type NotFound

type NotFound interface {
	NotFound(*app.JSONAPIErrors) error
}

NotFound represent a Context that can return a NotFound HTTP status

type Unauthorized

type Unauthorized interface {
	Unauthorized(*app.JSONAPIErrors) error
}

Unauthorized represent a Context that can return a Unauthorized HTTP status

Jump to

Keyboard shortcuts

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