From 443f4b8bdf64c6307a3ce8d9d5868dc44f7025b1 Mon Sep 17 00:00:00 2001 From: "konstantina.galouni" Date: Wed, 31 Aug 2022 13:09:53 +0000 Subject: [PATCH] [Trunk | Orcid Service]: WorkController.java & ExceptionsHandler.java: Added "contentNotFoundException" handler. --- .../uoaorcidservice/controllers/WorkController.java | 4 +++- .../uoaorcidservice/handlers/ExceptionsHandler.java | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) 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();