WebApplicationException 未显示错误消息
WebApplicationException is not showing the error message
我通过扩展 jax-rs api 的 WebApplicationException class 创建了自定义异常 class。我在错误的输入上抛出这个异常。
public class RestException extends WebApplicationException {
public RestException(String message, Response.Status status) {
super(message, status);
}
}
当我在我的应用程序中使用上述异常时,它正确返回了状态代码,但它没有返回我在构造函数中设置的错误消息。
如果我使用 jersey 而不是 cxf,它会同时显示错误消息和状态代码。对此有任何帮助....
我通过如下更改 RestException constructore 的签名来解决这个问题。
public class RestException extends WebApplicationException {
public RestException(String message, Response.Status status) {
super(Response.status(status).entity(message).type(MediaType.TEXT_PLAIN).build());
}
}
我通过扩展 jax-rs api 的 WebApplicationException class 创建了自定义异常 class。我在错误的输入上抛出这个异常。
public class RestException extends WebApplicationException {
public RestException(String message, Response.Status status) {
super(message, status);
}
}
当我在我的应用程序中使用上述异常时,它正确返回了状态代码,但它没有返回我在构造函数中设置的错误消息。
如果我使用 jersey 而不是 cxf,它会同时显示错误消息和状态代码。对此有任何帮助....
我通过如下更改 RestException constructore 的签名来解决这个问题。
public class RestException extends WebApplicationException {
public RestException(String message, Response.Status status) {
super(Response.status(status).entity(message).type(MediaType.TEXT_PLAIN).build());
}
}