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

Michael Burman miburman at redhat.com
Fri Mar 6 06:56:25 EST 2015


Hi,

This is what's done in the websocket branch currently:

    @Override
    public void onFailure(Throwable t) {
        Error errors = new Error(errorMsg + ": " + Throwables.getRootCause(t).getMessage());
        response.resume(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errors).type(
            MediaType.APPLICATION_JSON_TYPE).build());
    }

public class Error {
    private String errorMsg;

..

Currently with forced JSON.

  - Micke

----- Original Message -----
From: "Juraci Paixão Kröhling" <jpkroehling at redhat.com>
To: hawkular-dev at lists.jboss.org
Sent: Friday, March 6, 2015 1:30:15 PM
Subject: Re: [Hawkular-dev] [metrics] Consistent error replies from REST API

-----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-----
_______________________________________________
hawkular-dev mailing list
hawkular-dev at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/hawkular-dev



More information about the hawkular-dev mailing list