Hi,

There is the other way,

<code>
public void acceptRepresentation( Representation entity )
       throws ResourceException {
 try {
   // Set the response's status and entity
 } catch ( Exception e ) {

      getResponse().setStatus( new Status( Status.CLIENT_ERROR_NOT_FOUND, e
) );
      getResponse().setEntity( null ) ;

}
</code>

It will take the status to clients with the exception.

2008/8/23, Michael Dunn <[EMAIL PROTECTED]>:
>
> David,
> Thanks for your response.  I should have been more clear.  I was wondering
> the
> proper way from a service standpoint to return an error.
>
> For example when inheriting from Resource in the server, - if the following
> code
> generates an exception - is it better to return an error via the response
> or
> throw an exception?
>
> <code>
> public void acceptRepresentation(Representation entity)
>        throws ResourceException {
> try {
>    // Set the response's status and entity
> } catch (Exception e) {
>
>    // OPTION 1
>    // which is the best way to return an error?????
>    // set it in the response as follows
>    response.setStatus(Status.CLIENT_ERROR_NOT_FOUND);
>    response.setEntity("Error", MediaType.TEXT_PLAIN)
>
>    // OR
>    // OPTION 2
>    throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND, "Error", e);
> }
> }
> </code>
>
>
>

Reply via email to