i want to handle the error for the following controller method
@GetMapping(value= "search", params = {"id", "!name"})
public ResponseEntity<?> getMovieById(@RequestParam(name = "id") short id) {
Movie movie = this.movieService.getMovieById(id);
if(null == movie) {
throw new MovieNotFoundException("Unable to find moviee with id: " + id);
}
return ResponseEntity.ok(movie);
}
so if the id in the link nit found i'm throwing MovieNotFoundException.
but spring throw the following error:
Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: Could not write JSON: Unable to find com.movies.mmdbapi.model.Movie with id 6; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Unable to find com.movies.mmdbapi.model.Movie with id 6