Documentation ¶
Index ¶
- Constants
- func AbortWithError(gCtx *gin.Context, code int, err ...error)
- func AbortWithErrorAndStacktrace(gCtx *gin.Context, code int, err ...error)
- func AssertFirstGinError(t *testing.T, ginCtx *gin.Context, expectedStatusCode int, ...)
- func AssertGinErrors(t *testing.T, ginCtx *gin.Context, errors ...ErrorResponseAssertion)
- func AssertPreparedResponseStatusCode(t *testing.T, ginCtx *gin.Context, expectedStatusCode int)
- func AssertRequestResponse(t *testing.T, rec *httptest.ResponseRecorder, expectedStatusCode int, ...)
- func DontWriteErrors(gCtx *gin.Context)
- func ErrorHandlingMiddleware(gCtx *gin.Context)
- func FirstGinError(ginCtx *gin.Context) error
- func PanicCatchingMiddleware(gCtx *gin.Context)
- type ErrorMessage
- type ErrorResponse
- type ErrorResponseAssertion
- type MultiError
- type StatusCode
Constants ¶
const NoStatusCode = StatusCode(0)
Variables ¶
This section is empty.
Functions ¶
func AbortWithError ¶
AbortWithError aborts the current request.
func AbortWithErrorAndStacktrace ¶
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 ¶
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 ErrorHandlingMiddleware ¶
ErrorHandlingMiddleware takes the last registered Error and creates a response based on this error
func FirstGinError ¶ added in v2.16.0
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 ¶
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 MultiError ¶ added in v2.23.0
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