mirror of
https://github.com/kataras/iris.git
synced 2025-03-15 08:06:27 +01:00
add OmitErrorHandler on rest Options
This commit is contained in:
parent
18b85f14dd
commit
2eb56ab525
|
@ -839,9 +839,10 @@ func (ctx *Context) StopWithPlainError(statusCode int, err error) {
|
||||||
//
|
//
|
||||||
// If the status code is a failure one then
|
// If the status code is a failure one then
|
||||||
// it will also fire the specified error code handler.
|
// it will also fire the specified error code handler.
|
||||||
func (ctx *Context) StopWithJSON(statusCode int, jsonObject interface{}) {
|
func (ctx *Context) StopWithJSON(statusCode int, jsonObject interface{}) error {
|
||||||
ctx.StopWithStatus(statusCode)
|
ctx.StopWithStatus(statusCode)
|
||||||
ctx.JSON(jsonObject)
|
_, err := ctx.writeJSON(jsonObject, nil)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// StopWithProblem stops the handlers chain, writes the status code
|
// StopWithProblem stops the handlers chain, writes the status code
|
||||||
|
@ -850,10 +851,11 @@ func (ctx *Context) StopWithJSON(statusCode int, jsonObject interface{}) {
|
||||||
//
|
//
|
||||||
// If the status code is a failure one then
|
// If the status code is a failure one then
|
||||||
// it will also fire the specified error code handler.
|
// it will also fire the specified error code handler.
|
||||||
func (ctx *Context) StopWithProblem(statusCode int, problem Problem) {
|
func (ctx *Context) StopWithProblem(statusCode int, problem Problem) error {
|
||||||
ctx.StopWithStatus(statusCode)
|
ctx.StopWithStatus(statusCode)
|
||||||
problem.Status(statusCode)
|
problem.Status(statusCode)
|
||||||
ctx.Problem(problem)
|
_, err := ctx.Problem(problem)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// +------------------------------------------------------------+
|
// +------------------------------------------------------------+
|
||||||
|
@ -3769,6 +3771,11 @@ type JSON struct {
|
||||||
Secure bool `yaml:"Secure"` // if true then it prepends a "while(1);" when Go slice (to JSON Array) value.
|
Secure bool `yaml:"Secure"` // if true then it prepends a "while(1);" when Go slice (to JSON Array) value.
|
||||||
// proto.Message specific marshal options.
|
// proto.Message specific marshal options.
|
||||||
Proto ProtoMarshalOptions `yaml:"ProtoMarshalOptions"`
|
Proto ProtoMarshalOptions `yaml:"ProtoMarshalOptions"`
|
||||||
|
// If true and json writing failed then the error handler is skipped
|
||||||
|
// and it just returns to the caller.
|
||||||
|
//
|
||||||
|
// See StopWithJSON and x/errors package.
|
||||||
|
OmitErrorHandler bool `yaml:"OmitErrorHandler"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultJSONOptions is the optional settings that are being used
|
// DefaultJSONOptions is the optional settings that are being used
|
||||||
|
@ -3789,21 +3796,24 @@ func (j *JSON) IsDefault() bool {
|
||||||
// JSONP contains the options for the JSONP (Context's) Renderer.
|
// JSONP contains the options for the JSONP (Context's) Renderer.
|
||||||
type JSONP struct {
|
type JSONP struct {
|
||||||
// content-specific
|
// content-specific
|
||||||
Indent string
|
Indent string
|
||||||
Callback string
|
Callback string
|
||||||
|
OmitErrorHandler bool // See JSON.OmitErrorHandler.
|
||||||
}
|
}
|
||||||
|
|
||||||
// XML contains the options for the XML (Context's) Renderer.
|
// XML contains the options for the XML (Context's) Renderer.
|
||||||
type XML struct {
|
type XML struct {
|
||||||
// content-specific
|
// content-specific
|
||||||
Indent string
|
Indent string
|
||||||
Prefix string
|
Prefix string
|
||||||
|
OmitErrorHandler bool // See JSON.OmitErrorHandler.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Markdown contains the options for the Markdown (Context's) Renderer.
|
// Markdown contains the options for the Markdown (Context's) Renderer.
|
||||||
type Markdown struct {
|
type Markdown struct {
|
||||||
// content-specific
|
// content-specific
|
||||||
Sanitize bool
|
Sanitize bool
|
||||||
|
OmitErrorHandler bool // See JSON.OmitErrorHandler.
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -4020,7 +4030,11 @@ func (ctx *Context) JSON(v interface{}, opts ...JSON) (n int, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if n, err = ctx.writeJSON(v, options); err != nil {
|
if n, err = ctx.writeJSON(v, options); err != nil {
|
||||||
ctx.handleContextError(err)
|
// if no options are given or OmitErrorHandler is true
|
||||||
|
// then do call the error handler (which may lead to a cycle).
|
||||||
|
if options == nil || !options.OmitErrorHandler {
|
||||||
|
ctx.handleContextError(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -4115,7 +4129,9 @@ func (ctx *Context) JSONP(v interface{}, opts ...JSONP) (n int, err error) {
|
||||||
|
|
||||||
ctx.ContentType(ContentJavascriptHeaderValue)
|
ctx.ContentType(ContentJavascriptHeaderValue)
|
||||||
if n, err = WriteJSONP(ctx.writer, v, options, ctx.shouldOptimize()); err != nil {
|
if n, err = WriteJSONP(ctx.writer, v, options, ctx.shouldOptimize()); err != nil {
|
||||||
ctx.handleContextError(err)
|
if !options.OmitErrorHandler {
|
||||||
|
ctx.handleContextError(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -4211,7 +4227,9 @@ func (ctx *Context) XML(v interface{}, opts ...XML) (n int, err error) {
|
||||||
|
|
||||||
ctx.ContentType(ContentXMLHeaderValue)
|
ctx.ContentType(ContentXMLHeaderValue)
|
||||||
if n, err = WriteXML(ctx.writer, v, options, ctx.shouldOptimize()); err != nil {
|
if n, err = WriteXML(ctx.writer, v, options, ctx.shouldOptimize()); err != nil {
|
||||||
ctx.handleContextError(err)
|
if !options.OmitErrorHandler {
|
||||||
|
ctx.handleContextError(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -4261,7 +4279,7 @@ func (ctx *Context) Problem(v interface{}, opts ...ProblemOptions) (int, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.contentTypeOnce(ContentJSONProblemHeaderValue, "")
|
ctx.contentTypeOnce(ContentJSONProblemHeaderValue, "")
|
||||||
return ctx.JSON(v, options.JSON)
|
return ctx.writeJSON(v, &options.JSON)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteMarkdown parses the markdown to html and writes these contents to the writer.
|
// WriteMarkdown parses the markdown to html and writes these contents to the writer.
|
||||||
|
@ -4291,7 +4309,9 @@ func (ctx *Context) Markdown(markdownB []byte, opts ...Markdown) (n int, err err
|
||||||
|
|
||||||
ctx.ContentType(ContentHTMLHeaderValue)
|
ctx.ContentType(ContentHTMLHeaderValue)
|
||||||
if n, err = WriteMarkdown(ctx.writer, markdownB, options); err != nil {
|
if n, err = WriteMarkdown(ctx.writer, markdownB, options); err != nil {
|
||||||
ctx.handleContextError(err)
|
if !options.OmitErrorHandler {
|
||||||
|
ctx.handleContextError(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue
Block a user