Add serviceOrder rest services
[externalapi/nbi.git] / src / main / java / org / onap / nbi / exceptions / ApiExceptionHandler.java
1 package org.onap.nbi.exceptions;
2
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;
11
12 @ControllerAdvice
13 public class ApiExceptionHandler {
14
15     private static final Logger LOGGER = LoggerFactory.getLogger(ApiExceptionHandler.class);
16
17
18     @ExceptionHandler(BackendFunctionalException.class)
19     @ResponseBody
20     public ResponseEntity<ApiError> backendExceptionHandler(final BackendFunctionalException exception) {
21         ApiError apiError =
22                 new ApiError(String.valueOf(exception.getHttpStatus().value()), exception.getMessage(), "", "");
23         return new ResponseEntity<ApiError>(apiError, exception.getHttpStatus());
24     }
25
26     @ExceptionHandler(TechnicalException.class)
27     @ResponseBody
28     public ResponseEntity<ApiError> technicalExceptionHandler(final TechnicalException exception) {
29         ApiError apiError =
30                 new ApiError(String.valueOf(exception.getHttpStatus().value()), exception.getMessage(), "", "");
31         return new ResponseEntity<ApiError>(apiError, exception.getHttpStatus());
32     }
33
34     @ExceptionHandler(RestClientException.class)
35     @ResponseBody
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);
40     }
41
42     @ExceptionHandler(ValidationException.class)
43     @ResponseBody
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);
47     }
48 }