errorHandling

package
v2.3.13 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2022 License: Apache-2.0 Imports: 13 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 ErrorHandlingMiddleware

func ErrorHandlingMiddleware(gCtx *gin.Context)

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

func NewErrorEntry

func NewErrorEntry(httpStatus int, details string, appendStackTrace bool) error

func PanicCatchingMiddleware

func PanicCatchingMiddleware(gCtx *gin.Context)

Types

type ErrorMessage

type ErrorMessage struct {

	//A unique error id
	Id string `json:"id"`

	//The HTTP status which can result from this error
	Status string `json:"status"`

	//A message containing a detailed description
	Detail string `json:"detail"`
}

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

type ErrorResponse

type ErrorResponse []ErrorMessage

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