-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
We have a task to get better exception handling from the API and the
client. We'd like to have better error messages and possibly error
codes, as well as json serializable.
Today we throw the following exceptions:
ForbiddenException - thrown from ConsumerResource
NotFoundException - thrown from a few Resources
BadRequestException - thrown from almost all Resources
WebApplicationException (parent to the above) - called directly
The above exceptions extend WebApplicationException and for the
return type to be "text/plain", which means you can't parse
it as JSON on the client side. This is odd since all other responses
are in JSON, it would be nice to be consistent. Sadly it isn't
enough to leave off the type call as it will default to text/plain.
In order to get it serializable the thought is to create a class
to be used as the payload for the Exceptions, say something like
ExceptionMessage. This class will be annotated with JAXB objects
and can be used to return as JSON or XML based on the Accept header,
just like the other API calls do.
The thought is to have it contain the following:
* error code - int
* label - string
* display message - string (i18n probably)
We may not need the error code since the HTTP codes might be enough,
then we'd just need to have decent message strings.
HTTP status codes -
http://en.wikipedia.org/wiki/List_of_HTTP_status_codes
ResponseStatus javadoc -
http://bit.ly/aMhkkM
Now on the exception side, we can continue to create wrapper exceptions
like BadRequestException OR we could use standard exceptions and use
the RESTeasy ExceptionMapper to map a standard exception to a proper
Response code. I personally like the wrapper exceptions since it makes
it more explicit, then use the ExceptionMapper for a final catchall
like NullPointerException, and other gross things that we might want
to offer a nicer error message to easy the pain :)
All in all the main key is to identify better error messages that the
client can use and make it consistent for Resource developers.
jesus
- --
jesus m. rodriguez | jesusr(a)redhat.com
principal software engineer | irc: zeus
red hat systems management | 919.754.4413 (w)
rhce # 805008586930012 | 919.623.0080 (c)
+---------------------------------------------+
| "Those who cannot remember the past |
| are condemned to repeat it." |
| -- George Santayana |
+---------------------------------------------+
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Fedora -
http://enigmail.mozdev.org/
iEYEARECAAYFAku8+mcACgkQvJZ57YntiYOMKwCg1ZjNmJ9URIUHTd2OxzIG31FN
HkkAn0YPX+13VjO6X1O7H0ldz2iPEM3h
=luRo
-----END PGP SIGNATURE-----