This is the method I wrote for exception
@ExceptionHandler(value = HttpRequestMethodNotSupportedException.class)
@ResponseStatus(HttpStatus.METHOD_NOT_ALLOWED)
public @ResponseBody ErrorResponse handleRequestMethodNotSupportedException(HttpRequestMethodNotSupportedException ex){
return new ErrorResponse(HttpStatus.METHOD_NOT_ALLOWED.value(), ex.getMessage());
}
Now I am not able to figure out where and how to throw this exception?
@GetMapping
public ResponseEntity<List> getAllSuppliers() throws HttpRequestMethodNotSupportedException {
return new ResponseEntity<>(service.getAllSuppliers(), HttpStatus.OK);
}
this is my get method in controller so in postman if instead of get if I send post request then 405 error will be shown so how can I handle this. I tried using throws exception in method signature but it is not working
Pranoti11 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.