Last active
March 29, 2019 10:00
-
-
Save namila007/5f29b8ee9d424a2040bc48d53c1207d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ControllerAdvice | |
public class RestExceptionHandler extends ResponseEntityExceptionHandler | |
{ | |
@ExceptionHandler(ResourceNotFoundException.class) | |
public ResponseEntity<Object> resourceEntityNotFound( ResourceNotFoundException ex ) | |
{ | |
ApiError apiError = createError( ex.getLocalizedMessage(), HttpStatus.BAD_REQUEST, ex ); | |
return new ResponseEntity<>( apiError, apiError.getStatus() ); | |
} | |
private ApiError createError( String msg, HttpStatus status, Exception e ) | |
{ | |
ApiError apiError = new ApiError( status ); | |
apiError.setMessage( msg ); | |
apiError.setDebugMessage( e.getMessage() ); | |
return apiError; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@ResponseStatus(HttpStatus.NOT_FOUND) | |
public class ResourceNotFoundException extends RuntimeException | |
{ | |
public ResourceNotFoundException( String exception ) | |
{ | |
super( exception ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment