users@jersey.java.net

Re: [Jersey] Returning error messages

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 01 Oct 2008 11:02:25 +0100

On Oct 1, 2008, at 10:21 AM, tarjei wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Hi, is there a nice way to return error messages together with an
> error
> code?
>
> Usecase: If I return 400 Bad Request to a client, it would help the
> client a lot if the response also contained a hint on what the service
> thought was wrong (for example validation errors).
>

When you say "error message" do you mean a message that is sent as the
body of the response or do you mean a message that is part of the
response status line?

The latter is not supported. For the former you can use
Response.ResposneBuilder [1], perhaps in conjunction with
WebApplicationException [2], or mapping exceptions to responses using
ExceptionMapper [3] to set the body of the response.

Paul.

[1] https://jsr311.dev.java.net/nonav/releases/1.0/javax/ws/rs/core/Response.ResponseBuilder.html
[2] https://jsr311.dev.java.net/nonav/releases/1.0/javax/ws/rs/WebApplicationException.html
[3] https://jsr311.dev.java.net/nonav/releases/1.0/javax/ws/rs/ext/ExceptionMapper.html

> Regards,
> Tarjei
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.6 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFI40EtYVRKCnSvzfIRAgXqAKCia9+HFMER17by0hODTHJzKcMf7wCeOMVw
> xicHWvVVqKqQDthY1JWVCSA=
> =HBMK
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>