errorHandling

package
v2.21.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

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 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 string                 `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

type ErrorResponseAssertion

type ErrorResponseAssertion struct {
	StatusCode string
	Detail     string
}

Jump to

Keyboard shortcuts

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