16 package org.openkilda.northbound.utils;
18 import static java.lang.String.format;
26 import org.springframework.http.HttpHeaders;
27 import org.springframework.http.HttpStatus;
28 import org.springframework.http.ResponseEntity;
29 import org.springframework.web.bind.annotation.ControllerAdvice;
30 import org.springframework.web.bind.annotation.ExceptionHandler;
31 import org.springframework.web.context.request.WebRequest;
32 import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
34 import java.util.Optional;
52 switch (exception.getErrorType()) {
54 status = HttpStatus.NOT_FOUND;
57 status = HttpStatus.BAD_REQUEST;
59 case PARAMETERS_INVALID:
60 status = HttpStatus.BAD_REQUEST;
63 status = HttpStatus.CONFLICT;
66 status = HttpStatus.UNAUTHORIZED;
68 case OPERATION_TIMED_OUT:
70 status = HttpStatus.INTERNAL_SERVER_ERROR;
73 status = HttpStatus.INTERNAL_SERVER_ERROR;
78 exception.getErrorType().toString(), exception.getMessage(), exception.getErrorDescription());
80 logger.warn(
format(
"Error %s caught.", error), exception);
82 return super.handleExceptionInternal(exception, error,
new HttpHeaders(),
status, request);
90 HttpStatus
status, WebRequest request) {
91 String correlationId = Optional.ofNullable(request.getHeader(CORRELATION_ID)).orElse(DEFAULT_CORRELATION_ID);
95 logger.error(
format(
"Unknown error %s caught.", error), exception);
97 return super.handleExceptionInternal(exception, error,
headers,
status, request);
ResponseEntity< Object > handleExceptionInternal(Exception exception, Object body, HttpHeaders headers, HttpStatus status, WebRequest request)
static final String DEFAULT_CORRELATION_ID
static final String CORRELATION_ID
ResponseEntity< Object > handleMessageException(MessageException exception, WebRequest request)