问题:在以下示例中,带有void
返回类型的处理程序(如果已注释掉)可以正常工作。我得到HttpStatus
422。
如果我切换到使用VndErrors
的版本,处理程序将不再起作用,我得到HttpStatus
500,我找不到这种行为的原因。
@ControllerAdvice
@RequestMapping(produces = "application/vnd.error")
@ResponseBody
public class CurrencyCalculatorControllerAdvice {
// this works
@ExceptionHandler
@ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY)
private void handleCurrencyDetailsNotFoundException(CurrencyDetailsNotFoundException e) {}
@ExceptionHandler
@ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY)
private void handleCurrencyRateNotFoundException(CurrencyRateNotFoundException e) {}
// this does not work
@ExceptionHandler
@ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY)
VndErrors handleCurrencyDetailsNotFoundException(CurrencyDetailsNotFoundException e) {
return new VndErrors(e.getLogRef().assemble(), e.getMessage());
}
@ExceptionHandler
@ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY)
VndErrors handleCurrencyDetailsNotFoundException(CurrencyRateNotFoundException e) {
return new VndErrors(e.getLogRef().assemble(), e.getMessage());
}
}