[Trunk | Orcid Service]: WorkController.java & ExceptionsHandler.java: Added "contentNotFoundException" handler.

This commit is contained in:
Konstantina Galouni 2022-08-31 13:09:53 +00:00
parent 3956c6c2b5
commit 443f4b8bdf
2 changed files with 14 additions and 1 deletions

View File

@ -226,7 +226,9 @@ public class WorkController {
orcid_log.error("Updating work response code is: " + response.getStatusCode());
orcid_log.error("Unexpected Response: "+response.getBody());
if(response.getStatusCode() == HttpStatus.UNAUTHORIZED) {
if(response.getStatusCode() == HttpStatus.NOT_FOUND) {
throw new ContentNotFoundException("Work to update not found");
} else if(response.getStatusCode() == HttpStatus.UNAUTHORIZED) {
throw new AuthorizationServiceException("You are not allowed to update work");
} else if(response.getStatusCode() == HttpStatus.CONFLICT) {
throw new ConflictException("Work is already saved");

View File

@ -51,6 +51,17 @@ public class ExceptionsHandler {
// return new ResponseEntity<ExceptionResponse>(response, HttpStatus.FORBIDDEN);
// }
@ExceptionHandler(ContentNotFoundException.class)
public ResponseEntity<ExceptionResponse> contentNotFoundException(Exception ex) {
ExceptionResponse response = new ExceptionResponse();
response.setErrorCode("No content found");
response.setErrorMessage(ex.getMessage());
response.setErrors(ex.getMessage());
response.setStatus(HttpStatus.NOT_FOUND);
log.error("contentNotFound exception: " + response.getErrorCode()+ " - "+response.getErrorMessage());
return new ResponseEntity<ExceptionResponse>(response, HttpStatus.NOT_FOUND);
}
@ExceptionHandler(ForbiddenException.class)
public ResponseEntity<ExceptionResponse> forbiddenException(Exception ex) {
ExceptionResponse response = new ExceptionResponse();