Spring boot Custom Errors code example
Example 1: responseentity error message
@RequestMapping(method = RequestMethod.GET)
public ResponseEntity getUser(@RequestHeader(value="Access-key") String accessKey,
@RequestHeader(value="Secret-key") String secretKey) {
try {
return ResponseEntity
.status(HttpStatus.CREATED)
.body(this.userService.chkCredentials(accessKey, secretKey, timestamp));
}
catch(ChekingCredentialsFailedException e) {
e.printStackTrace();
return ResponseEntity
.status(HttpStatus.FORBIDDEN)
.body("Error Message");
}
}
Example 2: create spring 404 error controller
server.error.whitelabel.enabled=false