|
|
|
|
|
|
1
|
package dtos.error;
|
1
|
package dtos.error;
|
|
2
|
|
2
|
|
|
3
|
import io.zipcoder.tc_spring_poll_application.exception.ResourceNotFoundException;
|
3
|
import io.zipcoder.tc_spring_poll_application.exception.ResourceNotFoundException;
|
|
|
|
4
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
5
|
+import org.springframework.context.MessageSource;
|
|
4
|
import org.springframework.http.HttpStatus;
|
6
|
import org.springframework.http.HttpStatus;
|
|
5
|
import org.springframework.http.ResponseEntity;
|
7
|
import org.springframework.http.ResponseEntity;
|
|
6
|
import org.springframework.validation.FieldError;
|
8
|
import org.springframework.validation.FieldError;
|
|
|
|
|
|
|
15
|
|
17
|
|
|
16
|
@ControllerAdvice
|
18
|
@ControllerAdvice
|
|
17
|
public class RestExceptionHandler {
|
19
|
public class RestExceptionHandler {
|
|
|
|
20
|
+
|
|
|
|
21
|
+ @Autowired()
|
|
|
|
22
|
+ private MessageSource messageSource;
|
|
|
|
23
|
+
|
|
18
|
@ExceptionHandler(ResourceNotFoundException.class)
|
24
|
@ExceptionHandler(ResourceNotFoundException.class)
|
|
19
|
public ResponseEntity<?> handleResourceNotFoundException(ResourceNotFoundException rnfe, HttpServletRequest request) {
|
25
|
public ResponseEntity<?> handleResourceNotFoundException(ResourceNotFoundException rnfe, HttpServletRequest request) {
|
|
20
|
ErrorDetail errorDetail = new ErrorDetail();
|
26
|
ErrorDetail errorDetail = new ErrorDetail();
|
|
|
|
|
|
|
41
|
}
|
47
|
}
|
|
42
|
ValidationError validationError = new ValidationError();
|
48
|
ValidationError validationError = new ValidationError();
|
|
43
|
validationError.setCode(fe.getCode());
|
49
|
validationError.setCode(fe.getCode());
|
|
44
|
- validationError.setMessage(fe.getDefaultMessage());
|
|
|
|
|
|
50
|
+ validationError.setMessage(messageSource.getMessage(fe,null));
|
|
45
|
validationErrorList.add(validationError);
|
51
|
validationErrorList.add(validationError);
|
|
46
|
}
|
52
|
}
|
|
47
|
errorDetail.setTimeStamp(new Date().getTime());
|
53
|
errorDetail.setTimeStamp(new Date().getTime());
|