Я пытаюсь настроить сообщение об ошибке моего тела.
Моя версия для Springboot - 2.1.5. ВЫПУСК
Я хочу это:
{
"This should be application specific"
}
но я получаю это:
{
"timestamp": "2019-05-24T15:47:10.872+0000",
"status": 500,
"error": "Internal Server Error",
"message": "Not Found (404)",
"path": "/github/gifojhuinh4w5"
}
Мой класс исключений:
@ControllerAdvice
public class AppExceptionHandler extends ResponseEntityExceptionHandler {
@ExceptionHandler(Exception.class)
protected ResponseEntity<Object> handleConflict(Exception ex, WebRequest request) {
String bodyOfResponse = "This should be application specific";
return handleExceptionInternal(ex, bodyOfResponse,
new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR, request);
}
}
Мой класс, где фиксируется исключение
@Controller
@EnableAutoConfiguration
public class GitHub {
@RequestMapping(value ="/github/{usuario}", produces = "application/json; charset=UTF-8")
@ResponseBody
public ResponseEntity<Object> quantidadeRepositorios(@PathVariable(value = "usuario")String usuario) throws IOException {
HashMap<String, Integer> map = new HashMap<>();
RepositoryService service = new RepositoryService();
GitHubClient client = new GitHubClient();
Gson gson = new Gson();
client.setOAuth2Token("key");
map.put("Total",service.getRepositories(usuario).size()); // exception captured here
return new ResponseEntity<>(gson.toJson(map), HttpStatus.OK);
}
}