[Trunk | Orcid Service]: WorkController.java & ExceptionsHandler.java: Added "contentNotFoundException" handler.
This commit is contained in:
parent
3956c6c2b5
commit
443f4b8bdf
|
@ -226,7 +226,9 @@ public class WorkController {
|
||||||
orcid_log.error("Updating work response code is: " + response.getStatusCode());
|
orcid_log.error("Updating work response code is: " + response.getStatusCode());
|
||||||
orcid_log.error("Unexpected Response: "+response.getBody());
|
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");
|
throw new AuthorizationServiceException("You are not allowed to update work");
|
||||||
} else if(response.getStatusCode() == HttpStatus.CONFLICT) {
|
} else if(response.getStatusCode() == HttpStatus.CONFLICT) {
|
||||||
throw new ConflictException("Work is already saved");
|
throw new ConflictException("Work is already saved");
|
||||||
|
|
|
@ -51,6 +51,17 @@ public class ExceptionsHandler {
|
||||||
// return new ResponseEntity<ExceptionResponse>(response, HttpStatus.FORBIDDEN);
|
// 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)
|
@ExceptionHandler(ForbiddenException.class)
|
||||||
public ResponseEntity<ExceptionResponse> forbiddenException(Exception ex) {
|
public ResponseEntity<ExceptionResponse> forbiddenException(Exception ex) {
|
||||||
ExceptionResponse response = new ExceptionResponse();
|
ExceptionResponse response = new ExceptionResponse();
|
||||||
|
|
Loading…
Reference in New Issue