Handling exceptions

101 views
Skip to first unread message

Thomas Lefort

unread,
Aug 4, 2017, 12:08:58 PM8/4/17
to RestyGWT
Hi,

I am using Restygwt with jackson and it works brilliantly, thanks for a great library.

I do have an issue though is in handling the RequestException that is thrown from the server. I read that I can get the message using the method.getResponse().getText() but there is nothing in there for me.

This is typically what I would do:

Interface

    @POST
    @Path("/assets/user/create")
    @Consumes("application/json")
    void createUser(CreateUserDTO createUserDTO) throws RequestException;


Server side

    @Override
    public void createUser(CreateUserDTO createUserDTO) throws RequestException {
// some code
}

Client side

                try {
                    UserHelper.checkUserValues(createUserDTO);
                    requestAccessView.displayLoading("Saving user");
                    REST.withCallback(new MethodCallback<Void>() {
                        @Override
                        public void onFailure(Method method, Throwable exception) {
                            requestAccessView.hideLoading();
                            requestAccessView.displayUserCreationError("User could not be created, reason is " + method.getResponse().getText());
                        }

                        @Override
                        public void onSuccess(Method method, Void result) {
                            requestAccessView.hideLoading();
                            requestAccessView.displayCreationSuccess("Your user has been successfully created. " +
                                    "Our staff will contact you very shortly to validate your request and provide you access to the EO Broker.");
                        }
                    }).call(ServicesUtil.assetsService).createUser(createUserDTO);
                } catch (Exception e) {
                    requestAccessView.displayUserCreationError(e.getMessage());
                }


The message I get is 

User could not be created, reason is

Instead of, for instance,

User could not be created, reason is name already taken.


If I look at the response, I cannot see any message, content length is 0, etc... so maybe something on the server side then?

Any idea would be very much appreciated!

Thanks

Thomas Lefort

unread,
Aug 4, 2017, 12:28:36 PM8/4/17
to RestyGWT
gee, asking the question is finding the answer ;-)

I just had to add the following

@Provider
public class RequestExceptionMapper implements ExceptionMapper<RequestException> {
    @Override
    public Response toResponse(RequestException exception) {
        return Response.status(Response.Status.BAD_REQUEST).entity(exception.getMessage()).build();
    }
}

It was a jax rs issue, but I would have thought restyGWT would do this by default?
Reply all
Reply to author
Forward
0 new messages