I created One restful Api which has all the crud operations. when i am testing get employee By id i am not able to display error message. even though i am throwing exception when record not exists for that id.
Here is My Controller code...
@GetMapping("/employee/{id}")
public ResponseEntity<Employee> getEmployeeById(@PathVariable("id") long employeeId) throws ResourceNotFoundException{
Employee employee=service.getEmployeeById(employeeId).orElseThrow(()->new ResourceNotFoundException("Employee not found for this id :"+employeeId));
return new ResponseEntity<Employee>(employee, HttpStatus.OK);
and My Exception class code
package com.mystyle.exception;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus;
@ResponseStatus(value=HttpStatus.NOT_FOUND)
public class ResourceNotFoundException extends RuntimeException {
/**
*
*/
private static final long serialVersionUID = 1L;
public ResourceNotFoundException(String message){
super(message);
}
}
and my postman error message
{
"timestamp": "2020-05-19T06:21:10.172+00:00",
"status": 404,
"error": "Not Found",
"message": "",
"path": "/api/v1/employee/2"
}