【发布时间】:2018-06-02 14:46:37
【问题描述】:
我有一个请求映射 -
@RequestMapping("/fetchErrorMessages")
public @ResponseBody int fetchErrorMessages(@RequestParam("startTime") String startTime,@RequestParam("endTime") String endTime) throws Exception
{
if(SanityChecker.checkDateSanity(startTime)&&SanityChecker.checkDateSanity(endTime))
{
return 0;
}
else
{
throw new NotFoundException("Datetime is invalid");
}
}
如果 startTime 和 endTime 无效,我想抛出 500 错误但返回 JSON 中的异常字符串。但是,我得到一个 HTML 页面,而不是说
白标错误页面
此应用程序没有显式映射 /error,因此您将其视为后备。
2017 年 12 月 20 日星期三 10:49:37 IST
出现意外错误(类型=内部服务器错误,状态=500)。
日期时间无效
我想用 JSON 返回 500
{"error":"Date time format is invalid"}
我该怎么做?
【问题讨论】:
标签: java json spring spring-mvc spring-boot