views:

159

answers:

1

I wanted to know if theres a way to send a JSON data along with HTTP response code 500. Basically I want my rest client to know that there is some error on the backend and along with it send a JSON error data structure like this.

{"error" : [
          {"code": "1001", "desc": "Some error description"},
          {"code": "1002", "desc": "Some other error description"}
           ]
}

This is using the following java stack = Java 6/JAX-RS/Jersey/Tomcat

If not, then is there a way to send a custom response code along with JSON data. Basically looking from JAX-RS API it looks that you can only send JSON data along with 200 OK??

Any thoughts?? I am guessing RESTEasy would be the same, right??

A: 

You simply need to set the HTTP header response to whatever you want before starting to output the actual response using something like setStatus(). Response.status(500)

Ben S