1 package org.onap.nbi.exceptions;
3 import org.slf4j.Logger;
4 import org.slf4j.LoggerFactory;
5 import org.springframework.http.HttpStatus;
6 import org.springframework.http.ResponseEntity;
7 import org.springframework.web.bind.annotation.ControllerAdvice;
8 import org.springframework.web.bind.annotation.ExceptionHandler;
9 import org.springframework.web.bind.annotation.ResponseBody;
10 import org.springframework.web.client.RestClientException;
13 public class ApiExceptionHandler {
15 private static final Logger LOGGER = LoggerFactory.getLogger(ApiExceptionHandler.class);
18 @ExceptionHandler(BackendFunctionalException.class)
20 public ResponseEntity<ApiError> backendExceptionHandler(final BackendFunctionalException exception) {
22 new ApiError(String.valueOf(exception.getHttpStatus().value()), exception.getMessage(), "", "");
23 return new ResponseEntity<ApiError>(apiError, exception.getHttpStatus());
26 @ExceptionHandler(TechnicalException.class)
28 public ResponseEntity<ApiError> technicalExceptionHandler(final TechnicalException exception) {
30 new ApiError(String.valueOf(exception.getHttpStatus().value()), exception.getMessage(), "", "");
31 return new ResponseEntity<ApiError>(apiError, exception.getHttpStatus());
34 @ExceptionHandler(RestClientException.class)
36 public ResponseEntity<ApiError> RestClientExceptionHandler(final RestClientException exception) {
37 ApiError apiError = new ApiError("500", HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase(),
38 "Unable to " + "reach ONAP services", "");
39 return new ResponseEntity<ApiError>(apiError, HttpStatus.INTERNAL_SERVER_ERROR);
42 @ExceptionHandler(ValidationException.class)
44 public ResponseEntity<ApiError> ValidationExceptionHandler(final ValidationException exception) {
45 ApiError apiError = new ApiError("400", HttpStatus.BAD_REQUEST.getReasonPhrase(), exception.getMessages(), "");
46 return new ResponseEntity<ApiError>(apiError, HttpStatus.INTERNAL_SERVER_ERROR);