Skip to content

Commit

Permalink
handle error
Browse files Browse the repository at this point in the history
Change-Id: Idf5ad6bea38d1f9eba8ea7147f5bc8ad4484fa14
  • Loading branch information
Tevic committed Jan 26, 2022
1 parent bea5ca0 commit fdc890d
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions context.go
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
}

Expand Down

0 comments on commit fdc890d

Please sign in to comment.