Documentation ¶
Index ¶
- Constants
- func ErrorHandler(service *goa.Service, verbose bool) goa.Middleware
- func ErrorToJSONAPIError(ctx context.Context, err error) (app.JSONAPIError, int)
- func ErrorToJSONAPIErrors(ctx context.Context, err error) (*app.JSONAPIErrors, int)
- func JSONErrorResponse(ctx InternalServerErrorContext, err error) error
- type BadRequestContext
- type ConflictContext
- type ForbiddenContext
- type InternalServerErrorContext
- type NotFoundContext
- type UnauthorizedContext
Constants ¶
const ( ErrorCodeNotFound = "not_found" ErrorCodeBadParameter = "bad_parameter" ErrorCodeVersionConflict = "version_conflict" ErrorCodeUnknownError = "unknown_error" ErrorCodeConversionError = "conversion_error" ErrorCodeInternalError = "internal_error" ErrorCodeForbiddenError = "forbidden_error" ErrorCodeJWTSecurityError = "jwt_security_error" ErrorCodeDataConflict = "data_conflict_error" )
const (
// ErrorMediaIdentifier 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 ¶
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 ¶
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(ctx InternalServerErrorContext, err error) error
JSONErrorResponse auto maps the provided error to the correct response type If all else fails, InternalServerError is returned
Types ¶
type BadRequestContext ¶
type BadRequestContext interface { context.Context BadRequest(*app.JSONAPIErrors) error }
BadRequest represent a Context that can return a BadRequest HTTP status
type ConflictContext ¶
type ConflictContext interface { context.Context Conflict(*app.JSONAPIErrors) error }
Conflict represent a Context that can return a Conflict HTTP status
type ForbiddenContext ¶
type ForbiddenContext interface { context.Context Forbidden(*app.JSONAPIErrors) error }
Forbidden represent a Context that can return a Unauthorized HTTP status
type InternalServerErrorContext ¶
type InternalServerErrorContext interface { context.Context InternalServerError(*app.JSONAPIErrors) error }
InternalServerErrorContext represent a Context that can return a InternalServerError HTTP status
type NotFoundContext ¶
type NotFoundContext interface { context.Context NotFound(*app.JSONAPIErrors) error }
NotFound represent a Context that can return a NotFound HTTP status
type UnauthorizedContext ¶
Unauthorized represent a Context that can return a Unauthorized HTTP status