1
|
package eu.dnetlib.data.search.web.api;
|
2
|
|
3
|
|
4
|
import org.springframework.http.HttpStatus;
|
5
|
import org.springframework.http.ResponseEntity;
|
6
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
7
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
8
|
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
9
|
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
|
10
|
|
11
|
@EnableWebMvc
|
12
|
@ControllerAdvice(value = "eu.dnetlib.data.search.web.api", assignableTypes = SearchRequestController.class)
|
13
|
public class ExceptionController extends ResponseEntityExceptionHandler{
|
14
|
@ExceptionHandler(Exception.class)
|
15
|
public ResponseEntity<Error> invalidInput(Exception ex) {
|
16
|
Error response = new Error();
|
17
|
response.setStatus("error");
|
18
|
response.setCode("500");
|
19
|
response.setMessage("500 - Internal server error.");
|
20
|
response.setException(ex.getMessage());
|
21
|
|
22
|
return new ResponseEntity<Error>(response, HttpStatus.CONFLICT);
|
23
|
}
|
24
|
}
|