当前位置: 动力学知识库 > 问答 > 编程问答 >

java - RestEasy 2.3 proxyclient framework does not catch exceptions

问题描述:

I'm trying to use the RestEasy client framework to query a REST service, while catching exceptions for http errors like 400, 404, 500, etc.

https://docs.jboss.org/resteasy/docs/2.2.1.GA/userguide/html/RESTEasy_Client_Framework.html#Client_error_handling

ResteasyProviderFactory instance=ResteasyProviderFactory.getInstance();

instance.registerProvider(ResteasyJacksonProvider.class);

RegisterBuiltin.register(instance);

UserServiceRest userService = ProxyFactory.create(UserServiceRest.class, "https://...");

try {

userService.getByUsername(onboardUsername);

userAlreadyOnboarded = true;

} catch (NotFoundException e) { // Want this to catch 404's

userAlreadyOnboarded = false;

} catch (ClientResponseFailure e) { // This catches the 404 instead, which I dont want

logger.error("ClientResponseFailure caught", e);

}

Running this code, I get the error:

org.jboss.resteasy.client.ClientResponseFailure: RESTEASY001130: Error status 404 Not Found returned

which is caught by the ClientResponseFailure, a RuntimeException.

The RESTEasy_Client_Framework documentation says I'm supposed to register a ClientErrorInterceptor to handle ClientResponseFailure and throw custom checked Exceptions. Does RestEasy have a built-in method of catching standard checked exceptions like NotFoundException or BadRequestException?

Here's the UserServiceRest interface, it's probably not important though.

@Path("/rest")

public interface UserServiceRest {

@GET

@Path("/byUsername/{username}")

@Produces(MediaType.APPLICATION_JSON)

public UserInfo getByUsername(@PathParam(value = "username") String username);

}

分享给朋友:
您可能感兴趣的文章:
随机阅读: