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
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)
render(status:500,text:(errors as JSON).toString(),contentType: 'application/json')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With