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