[Hawkular-dev] [metrics] Consistent error replies from REST API

Juraci Paixão Kröhling jpkroehling at redhat.com
Fri Mar 6 06:30:15 EST 2015


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 03/06/2015 12:11 PM, Heiko W.Rupp wrote:
> 
>> Am 06.03.2015 um 11:07 schrieb Juraci Paixão Kröhling
>> <jpkroehling at redhat.com>: For scenarios where things were really
>> expected to be there but aren't, exceptions are fine. For
>> scenarios where the user asked for something that didn't exist,
>> input checking and promptly returning a 404 makes more sense,
>> IMO.
> 
> I fear that this will lead to pretty unreadable code with many
> blocks of
> 
> return Response.Builder.notFound(new StringEntity("this is my
> message %s",bla)).type("application/json").build()
> 
> While we do (only) application/json right now, this will get more
> complex with more (custom) media types.

How about then making beans for representing the responses and letting
the JAX-RS convert it to the appropriate media type? The disadvantage
is that each "response" structure requires a class. The advantage is
that it's well documented what is the response's structure.

class ErrorResponseBean {
  String message;
}

ResponseBean bean = new ErrorResponseBean("this is my message %s",bla);
Response.notFound().entity(bean).build();

- - Juca.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1

iQEcBAEBAgAGBQJU+Y/HAAoJECKM1e+fkPrXKLUH/2RYlwMACfK42JODX4w3BAc4
Lj1c4ObCkgHvLtP11/m8nA+HZwegFVqqJQZSYji3q9WYfLPBsQeRJv9Yciii5VnE
UaqxGwPRyxx6nVluPK4gBX8qirKFZh05kM6vRAotjYtnK8+BnxnEb38UmYVuhFL6
HIglliwtVqIK9CWmUn7atPCK7d6o0k3/xC1Kh0435dv85evC0kVr8w7eORC1iWjF
EBoHOvdYHl+rrvsOJyIXZERxhVhx4JD/gydsvKD5IBc4Q38fI0yXVtQdutsaufpW
CEwI2SrSZjZ9T2J9oVRUT8KgD/9GPNwTjGCmVu1e4tAq/yR57pj0OoY7gpjf640=
=+Q8p
-----END PGP SIGNATURE-----


More information about the hawkular-dev mailing list