答案 0 :(得分:0)
据我了解,如果服务没有响应,路由丢失等,您可以设置/ error端点以向用户传递自定义响应。 例如:
@Controller
public class CustomErrorController implements ErrorController {
@RequestMapping(value = "/error", produces = "application/json")
public @ResponseBody
ResponseEntity error(HttpServletRequest request) {
// consider putting these in a try catch
Integer statusCode = (Integer)request.getAttribute("javax.servlet.error.status_code");
Throwable exception = (Throwable)request.getAttribute("javax.servlet.error.exception");
// maybe add some error logging here, e.g. original status code, exception, traceid, etc.
// consider a better error to the user here
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("{'message':'some error happened', 'trace_id':'some-trace-id-here'}");
}
@Override
public String getErrorPath() {
return "/error";
}
}