1
|
package eu.dnetlib.uoaadmintools.controllers;
|
2
|
|
3
|
import eu.dnetlib.uoaadmintools.responses.ExceptionResponse;
|
4
|
|
5
|
import org.springframework.http.HttpStatus;
|
6
|
import org.springframework.http.ResponseEntity;
|
7
|
import org.springframework.web.bind.MissingServletRequestParameterException;
|
8
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
9
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
10
|
|
11
|
@ControllerAdvice
|
12
|
public class ExceptionController {
|
13
|
|
14
|
@ExceptionHandler(MissingServletRequestParameterException.class)
|
15
|
public ResponseEntity<ExceptionResponse> invalidInput(Exception ex) {
|
16
|
ExceptionResponse response = new ExceptionResponse();
|
17
|
response.setErrorCode("Validation Error");
|
18
|
response.setErrorMessage("Invalid inputs.");
|
19
|
response.setErrors(ex.getMessage());
|
20
|
|
21
|
return new ResponseEntity<ExceptionResponse>(response, HttpStatus.BAD_REQUEST);
|
22
|
}
|
23
|
}
|