|
|
|
|
445
|
- Use java.util's `new Date().getTime()` for the timestamp
|
445
|
- Use java.util's `new Date().getTime()` for the timestamp
|
446
|
- Provide the detail and developer messages from the `ResourceNotFoundException`
|
446
|
- Provide the detail and developer messages from the `ResourceNotFoundException`
|
447
|
|
447
|
|
448
|
-```
|
|
|
|
|
448
|
+```java
|
449
|
@ExceptionHandler(ResourceNotFoundException.class)
|
449
|
@ExceptionHandler(ResourceNotFoundException.class)
|
450
|
public ResponseEntity<?> handleResourceNotFoundException(ResourceNotFoundException rnfe, HttpServletRequest request) {...}
|
450
|
public ResponseEntity<?> handleResourceNotFoundException(ResourceNotFoundException rnfe, HttpServletRequest request) {...}
|
451
|
```
|
451
|
```
|
|
|
|
|
475
|
|
475
|
|
476
|
- add below handler to `RestExceptionHandler`
|
476
|
- add below handler to `RestExceptionHandler`
|
477
|
|
477
|
|
478
|
-```
|
|
|
|
|
478
|
+```java
|
479
|
@ExceptionHandler(MethodArgumentNotValidException.class)
|
479
|
@ExceptionHandler(MethodArgumentNotValidException.class)
|
480
|
public ResponseEntity<?>
|
480
|
public ResponseEntity<?>
|
481
|
handleValidationError( MethodArgumentNotValidException manve,
|
481
|
handleValidationError( MethodArgumentNotValidException manve,
|
|
|
|
|
489
|
- For each field error, add it to the appropriate list in the ErrorDetail (see below)
|
489
|
- For each field error, add it to the appropriate list in the ErrorDetail (see below)
|
490
|
- Return a `ResponseEntity` containing the error detail and the appropriate HTTP status code (`400 Bad Request`)
|
490
|
- Return a `ResponseEntity` containing the error detail and the appropriate HTTP status code (`400 Bad Request`)
|
491
|
|
491
|
|
492
|
-```
|
|
|
|
|
492
|
+```java
|
493
|
List<FieldError> fieldErrors = manve.getBindingResult().getFieldErrors();
|
493
|
List<FieldError> fieldErrors = manve.getBindingResult().getFieldErrors();
|
494
|
for(FieldError fe : fieldErrors) {
|
494
|
for(FieldError fe : fieldErrors) {
|
495
|
|
495
|
|