Reputation: 32086
Is there a shorthand way to do this without explicit "text/json"
designation?
def remoteError = {
render( status: 500, contentType: "text/json"){
error( exception: "a remote exception occurred")
}
}
I tried using as JSON
...no content is returned but the status code is correct...
render( status: 500, exception: params.exception) as JSON
Upvotes: 23
Views: 15849
Reputation: 4126
render(status:500,text:(errors as JSON).toString(),contentType: 'application/json')
Upvotes: 3
Reputation: 29629
If you use a converter parameter to render then you cannot specify any other parameter such as status like you normally would when using gsp views. You can however set the response status prior to calling render:
response.status = 500
render([error: 'an error occurred'] as JSON)
Upvotes: 45