views:

19

answers:

2

Hi,

We are using content negotiation in our service using the Accept header and the withFormat method....the issue we are facing is that we want to return a 406 http status if the Accept header has a type which is not supported by our service....can anybody give us some ideas on how would we go about doing this ?

Thanks, VK

+1  A: 
  return withFormat {
     html {
        render(view: "itWorked", model: data)
     }
     json {
        render(data as JSON)
     }
     xml {
        render(data as XML)
     }
  }

  render(status: 406, text: 'ERROR')
Aaron Saunders
A: 

this seems to acting a bit strange...so what I have now is:

return withFormat{
     json{
         render(data as JSON)
         }
     xml{
         render(data as XML)
         }
  }
  render(status: 406, text: 'ERROR')

Now when I set the Accept header to application/json, or application/xml it seems to work fine....but if I set the header to something which is not supported like text/html then I get back a 404 and not a 406....Also another strange behaviour I see is that if I set the header to something like text/plain or text/csv, the request.format parameter gets set to html in the controller....any idea why this is happening?

VKA