VKA
VKA

Reputation: 1

Grails Content Negotiation - handling unsupported type

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?

Upvotes: 0

Views: 357

Answers (1)

Aaron Saunders
Aaron Saunders

Reputation: 33345

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

  render(status: 406, text: 'ERROR')

Upvotes: 1

Related Questions