diff --git a/src/main/java/eu/dnetlib/uoaorcidservice/controllers/WorkController.java b/src/main/java/eu/dnetlib/uoaorcidservice/controllers/WorkController.java index 5d868a9..6514fd0 100644 --- a/src/main/java/eu/dnetlib/uoaorcidservice/controllers/WorkController.java +++ b/src/main/java/eu/dnetlib/uoaorcidservice/controllers/WorkController.java @@ -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"); diff --git a/src/main/java/eu/dnetlib/uoaorcidservice/handlers/ExceptionsHandler.java b/src/main/java/eu/dnetlib/uoaorcidservice/handlers/ExceptionsHandler.java index 437cb62..5206563 100644 --- a/src/main/java/eu/dnetlib/uoaorcidservice/handlers/ExceptionsHandler.java +++ b/src/main/java/eu/dnetlib/uoaorcidservice/handlers/ExceptionsHandler.java @@ -51,6 +51,17 @@ public class ExceptionsHandler { // return new ResponseEntity(response, HttpStatus.FORBIDDEN); // } + @ExceptionHandler(ContentNotFoundException.class) + public ResponseEntity 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(response, HttpStatus.NOT_FOUND); + } + @ExceptionHandler(ForbiddenException.class) public ResponseEntity forbiddenException(Exception ex) { ExceptionResponse response = new ExceptionResponse();