errorHandling

package
v2.23.0 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const NoStatusCode = StatusCode(0)

Variables

This section is empty.

Functions

func AbortWithError

func AbortWithError(gCtx *gin.Context, code int, err ...error)

AbortWithError aborts the current request.

func AbortWithErrorAndStacktrace

func AbortWithErrorAndStacktrace(gCtx *gin.Context, code int, err ...error)

AbortWithErrorAndStacktrace aborts the current request; it attaches the stack trace to the error; it will be printed into the logs but not as response.

func AssertFirstGinError

func AssertFirstGinError(t *testing.T, ginCtx *gin.Context, expectedStatusCode int, expectedErrorMessage string)

AssertFirstGinError checks the enlisted errors within gin.Context. The assertion looks for the first error; it shall be an error submitted by AbortWithError or AbortWithErrorAndStacktrace

func AssertGinErrors added in v2.23.0

func AssertGinErrors(t *testing.T, ginCtx *gin.Context, errors ...ErrorResponseAssertion)

AssertGinErrors checks the enlisted errors within gin.Context. The assertion looks for any error submitted by AbortWithError or AbortWithErrorAndStacktrace

func AssertPreparedResponseStatusCode

func AssertPreparedResponseStatusCode(t *testing.T, ginCtx *gin.Context, expectedStatusCode int)

AssertPreparedResponseStatusCode checks the current gin.Context to not have a committed HTTP status code within the response It searches the enlisted errors for a prepared status code which will be picked up by ErrorHandlingMiddleware

func AssertRequestResponse

func AssertRequestResponse(t *testing.T, rec *httptest.ResponseRecorder, expectedStatusCode int, errors ...ErrorResponseAssertion)

AssertRequestResponse checks the recorded response for a httptest.ResponseRecorder

func DontWriteErrors added in v2.9.0

func DontWriteErrors(gCtx *gin.Context)

func ErrorHandlingMiddleware

func ErrorHandlingMiddleware(gCtx *gin.Context)

ErrorHandlingMiddleware takes the last registered Error and creates a response based on this error

func FirstGinError added in v2.16.0

func FirstGinError(ginCtx *gin.Context) error

FirstGinError checks the enlisted errors within gin.Context. It returns the first error; it shall be an error submitted by AbortWithError or AbortWithErrorAndStacktrace

func PanicCatchingMiddleware

func PanicCatchingMiddleware(gCtx *gin.Context)

Types

type ErrorMessage

type ErrorMessage struct {
	Id     string                 `json:"id"`             //A unique error id
	Status StatusCode             `json:"status"`         //The HTTP status which can result from this error
	Detail string                 `json:"detail"`         //A message containing a detailed description
	Meta   map[string]interface{} `json:"meta,omitempty"` //A meta object containing non-standard meta-information about the error.
	Code   *string                `json:"code,omitempty"` //An application-specific error code, expressed as a string value.
}

ErrorMessage is a representation of an error based on https://jsonapi.org/format/#errors

func (*ErrorMessage) Error added in v2.16.0

func (e *ErrorMessage) Error() string

type ErrorResponse

type ErrorResponse []ErrorMessage

func (ErrorResponse) Error added in v2.16.0

func (e ErrorResponse) Error() string

func (ErrorResponse) WrappedErrors added in v2.23.0

func (e ErrorResponse) WrappedErrors() []error

type ErrorResponseAssertion

type ErrorResponseAssertion struct {
	StatusCode int
	Detail     string
}

type MultiError added in v2.23.0

type MultiError interface {
	error
	WrappedErrors() []error
}

type StatusCode added in v2.23.0

type StatusCode int

func (StatusCode) MarshalJSON added in v2.23.0

func (s StatusCode) MarshalJSON() ([]byte, error)

func (*StatusCode) UnmarshalJSON added in v2.23.0

func (s *StatusCode) UnmarshalJSON(bytes []byte) error

Jump to

Keyboard shortcuts

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