Extend error with isUserError flag, to catch user and internal server exceptions
This commit is contained in:
parent
b9a98d9e0b
commit
16b3f085cb
3 changed files with 11 additions and 5 deletions
|
|
@ -12,6 +12,10 @@ public class GlobalExceptionHandler {
|
|||
|
||||
@ExceptionHandler(value = SignalErrorException.class, produces = MediaType.APPLICATION_XML_VALUE)
|
||||
public ResponseEntity<CommonError> handleInvalidUser(SignalErrorException ex) {
|
||||
return ResponseEntity.badRequest().body(ex.getError());
|
||||
if (ex.isUserError()) {
|
||||
return ResponseEntity.badRequest().body(ex.getError());
|
||||
} else {
|
||||
return ResponseEntity.internalServerError().body(ex.getError());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,9 +7,11 @@ import ru.nbch.credit_tracker.enums.SignalError;
|
|||
@Getter
|
||||
public class SignalErrorException extends RuntimeException {
|
||||
|
||||
private final boolean isUserError;
|
||||
private final CommonError error;
|
||||
|
||||
public SignalErrorException(SignalError signalError, String tag, CommonError error) {
|
||||
public SignalErrorException(SignalError signalError, String tag, CommonError error, boolean isUserError) {
|
||||
this.isUserError = isUserError;
|
||||
this.error = createErrorMessage(error, signalError, tag);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -264,20 +264,20 @@ public class SignalFacade {
|
|||
try {
|
||||
AuthorizationService.AuthResult authResult = authorizationService.findAuthInfo(activePackagesRequest.getUserId(), activePackagesRequest.getPassword());
|
||||
if (!authResult.isSuccess()) {
|
||||
throw new SignalErrorException(authResult.getError(), null, new MonitoringActivePackagesError());
|
||||
throw new SignalErrorException(authResult.getError(), null, new MonitoringActivePackagesError(), true);
|
||||
}
|
||||
MonitoringActivePackagesResponse response = signalService.findActivePackages(activePackagesRequest.getUserId());
|
||||
if (response != null) {
|
||||
return ResponseEntity.ok(response);
|
||||
} else {
|
||||
throw new SignalErrorException(SignalError.ERROR_015, null, new MonitoringActivePackagesError());
|
||||
throw new SignalErrorException(SignalError.ERROR_015, null, new MonitoringActivePackagesError(), true);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (e instanceof SignalErrorException) {
|
||||
throw (SignalErrorException) e;
|
||||
}
|
||||
log.error(e.getMessage(), e);
|
||||
throw new SignalErrorException(SignalError.ERROR_013, null, new MonitoringActivePackagesError());
|
||||
throw new SignalErrorException(SignalError.ERROR_013, null, new MonitoringActivePackagesError(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue