我的 springbootapp 中有一个处理程序类,它对传入的 REST 请求执行一些验证并将 BadRequestException 抛回控制器类。
但不是控制器捕获 BadRequestException,而是捕获异常并抛出
java.lang.ClassNotFoundException:org.glassfish.jersey.internal.RuntimeDelegateImpl
我花了一些时间四处寻找解决方案,但似乎没有找到任何解决方案。
这是我在处理程序中的验证代码
private void validateSignUpRequest(String phone) {
if(StringUtils.isEmpty(phone))
throw new BadRequestException("Phone Number can't be empty");
}
这是控制器
@PostMapping(path = "/users/sign-up")
public ResponseEntity<UserData> signUpUser(@RequestBody Users user) {
UserData userData = null;
HttpStatus httpStatus = null;
boolean flag = false;
try {
userData = userHandler.fetchByPhone(user.getPhoneNumber());
if (userData == null) {
flag = userHandler.saveUser(user);
httpStatus = HttpStatus.CREATED;
} else {
userData = UserData.failureResponse("User Already Exist");
httpStatus = HttpStatus.CONFLICT;
}
}catch(BadRequestException e) {
userData = UserData.failureResponse(e.getMessage());
httpStatus = HttpStatus.BAD_REQUEST;
}
catch (Exception e) {
userData = UserData.failureResponse(e.getMessage());
httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;
}
return new ResponseEntity<>(userData,httpStatus);
}
四季花海
相关分类