From 012c935a465079ae7edc75cce9100a13b3d2cd8e Mon Sep 17 00:00:00 2001 From: Manu Mtz-Almeida Date: Sun, 31 Aug 2014 18:41:11 +0200 Subject: [PATCH] Better errors in Context.Negotiation --- context.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/context.go b/context.go index 123d257d..178379b8 100644 --- a/context.go +++ b/context.go @@ -292,8 +292,7 @@ type Negotiate struct { } func (c *Context) Negotiate(code int, config Negotiate) { - result := c.NegotiateFormat(config.Offered...) - switch result { + switch c.NegotiateFormat(config.Offered...) { case MIMEJSON: data := chooseData(config.JSONData, config.Data) c.JSON(code, data) @@ -310,11 +309,14 @@ func (c *Context) Negotiate(code int, config Negotiate) { c.XML(code, data) default: - c.Fail(400, errors.New("m")) + c.Fail(http.StatusNotAcceptable, errors.New("the accepted formats are not offered by the server")) } } func (c *Context) NegotiateFormat(offered ...string) string { + if len(offered) == 0 { + panic("you must provide at least one offer") + } if c.accepted == nil { c.accepted = parseAccept(c.Request.Header.Get("Accept")) }