From fdc890d82bf1e5d9e50908e2c3f106827086d8ae Mon Sep 17 00:00:00 2001 From: Tevic Date: Wed, 26 Jan 2022 11:41:15 +0800 Subject: [PATCH] handle error Change-Id: Idf5ad6bea38d1f9eba8ea7147f5bc8ad4484fa14 --- context.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/context.go b/context.go index 387988d0fc..8b5bd5019d 100644 --- a/context.go +++ b/context.go @@ -195,9 +195,9 @@ func (c *Context) AbortWithStatus(code int) { // AbortWithStatusJSON calls `Abort()` and then `JSON` internally. // This method stops the chain, writes the status code and return a JSON body. // It also sets the Content-Type as "application/json". -func (c *Context) AbortWithStatusJSON(code int, jsonObj interface{}) { +func (c *Context) AbortWithStatusJSON(code int, jsonObj interface{}) error { c.Abort() - c.JSON(code, jsonObj) + return c.JSON(code, jsonObj) } // AbortWithError calls `AbortWithStatus()` and `Error()` internally. @@ -1062,26 +1062,26 @@ type Negotiate struct { } // Negotiate calls different Render according to acceptable Accept format. -func (c *Context) Negotiate(code int, config Negotiate) { +func (c *Context) Negotiate(code int, config Negotiate) error { switch c.NegotiateFormat(config.Offered...) { case binding.MIMEJSON: data := chooseData(config.JSONData, config.Data) - c.JSON(code, data) + return c.JSON(code, data) case binding.MIMEHTML: data := chooseData(config.HTMLData, config.Data) - c.HTML(code, config.HTMLName, data) + return c.HTML(code, config.HTMLName, data) case binding.MIMEXML: data := chooseData(config.XMLData, config.Data) - c.XML(code, data) + return c.XML(code, data) case binding.MIMEYAML: data := chooseData(config.YAMLData, config.Data) - c.YAML(code, data) + return c.YAML(code, data) default: - c.AbortWithError(http.StatusNotAcceptable, errors.New("the accepted formats are not offered by the server")) // nolint: errcheck + return c.AbortWithError(http.StatusNotAcceptable, errors.New("the accepted formats are not offered by the server")) // nolint: errcheck } }