请参阅下面的资源。我在postjut中设置了抛出异常来测试异常Map器是否工作,但它从未被调用。相反,我得到“红屏”从 quarkus 错误信息与stacktrace请帮助
@RouteBase(path = "login", produces = APPLICATION_JSON)
public class LoginResource {
@ServerExceptionMapper
public RestResponse<String> mapException(AuthConsentException x) {
return RestResponse.status(Response.Status.NOT_FOUND, "message");
}
@Inject
LoginService loginService;
@Route(path = "/provider", methods = POST, consumes = APPLICATION_FORM_URLENCODED)
public void post(RoutingContext routingContext,
@Param(LOGIN_CHALLENGE) @NotBlank(message = LOGIN_CHALLENGE + PARAMETER_SHOULD_BE_SET) String challenge,
@Param(PROVIDER) @NotBlank(message = PROVIDER + PARAMETER_SHOULD_BE_SET) String provider) {
throw new AuthConsentException("test");
// loginService.post(routingContext, challenge, provider);
}
}
字符串
我也试着使用,但它从来没有得到相同的调用
@Provider
public class AuthConsentExceptionMapper implements ExceptionMapper<AuthConsentException> {
private static final String ERROR_LOG_PATTERN = "%s, id:%s";
@Override
public Response toResponse(AuthConsentException e) {
ErrorDTO error = new ErrorDTO(e.getMessage());
Log.errorf(ERROR_LOG_PATTERN, e.getMessage(), error.getId());
return Response.status(INTERNAL_SERVER_ERROR)
.type(APPLICATION_JSON_TYPE)
.entity(error).build();
}
}
型
2条答案
按热度按时间k75qkfdt1#
Reactive Routes(
@Route
注解的来源)不支持来自RESTEasy Reactive的任何特性。因此,最好的办法是将
LoginResource
重写为Jakarta REST资源。vyswwuz22#
找到原因了。使用React式路由时,不调用异常处理程序,而应按如下方式使用
字符串