1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-18 02:17:05 +00:00
Former-commit-id: 55589069c8ed458183d28f32870fdf8f233629c6
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-07-11 16:14:31 +03:00
parent 3574816e1d
commit c8ed26ee51
8 changed files with 981 additions and 923 deletions

View File

@@ -4505,6 +4505,32 @@ func (ctx *Context) Application() Application {
return ctx.app
}
const errorContextKey = "iris.context.error"
// SetErr is just a helper that sets an error value
// as a context value, it does nothing more.
// Also, by-default this error's value is written to the client
// on failures when no registered error handler is available (see `Party.On(Any)ErrorCode`).
// See `GetError` to retrieve it back.
//
// Note that, if you want to stop the chain
// with an error see the `StopWithError` instead.
func (ctx *Context) SetErr(err error) {
ctx.Values().Set(errorContextKey, err)
}
// GetErr is a helper which retrieves
// the error value stored by `SetErr`.
func (ctx *Context) GetErr() error {
if v := ctx.Values().Get(errorContextKey); v != nil {
if err, ok := v.(error); ok {
return err
}
}
return nil
}
const idContextKey = "iris.context.id"
// SetID sets an ID, any value, to the Request Context.