Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ErrorMiddleware ¶ added in v0.1.0
ErrorMiddleware allows for Errors to be attached to a request. It uses a global cache with the request id as a key, it therefore requires chi`s RequestId middleware!
If errors are present a 500 code will be returned and the errors encoded as json.
The GetErrors function and the Errors interface can be used without this middleware (only requiring chi`s RequestId) so you can write your own error handler!
Types ¶
type Errors ¶
type Errors interface { // Id returns the request id given to the context`s request by chi`s RequestId middlware Id() string // Errors returns the attached errors Errors() []error // AddError can be used to add an error AddError(err error) // Done should only be called once the response has reached to error handler, // and the errors can be deleted from the cache. // // Since this clears the cache for the associated request id, // using Errors or AddError after this call will cause a panic! Done() }
Errors can be used to read and add errors to the error cache for this request!
This requires only chi`s RequestId middleware, while you can use the ErrorMiddleware to handle the returned errors you can also write your own!
Click to show internal directories.
Click to hide internal directories.