use of com.github.lybgeek.circuitbreaker.framework.ciruitbreaker.model.AjaxResult in project springboot-learning by lyb-geek.
the class DefaultBlockExceptionHandler method handle.
@Override
public void handle(HttpServletRequest request, HttpServletResponse response, BlockException e) throws Exception {
response.setStatus(200);
response.setCharacterEncoding("utf-8");
response.setContentType("application/json; charset=utf-8");
StringBuffer url = request.getRequestURL();
if ("GET".equals(request.getMethod()) && StringUtil.isNotBlank(request.getQueryString())) {
url.append("?").append(request.getQueryString());
}
String msg = "Blocked by Sentinel Flow Limit";
log.error("sentinel flow limit url:{}", url);
if (e instanceof AuthorityException) {
msg = "Blocked by Sentinel Authority Limit";
} else if (e instanceof SystemBlockException) {
msg = "Blocked by Sentinel System Limit";
} else if (e instanceof DegradeException) {
msg = "Blocked by Sentinel Degrade Limit";
} else if (e instanceof ParamFlowException) {
msg = "Blocked by Sentinel ParamFlow Limit";
}
AjaxResult result = new AjaxResult();
result.setSuccess(false);
result.setCode(429);
result.setMessage(msg);
OutputStream out = response.getOutputStream();
out.write(JSON.toJSONString(result).getBytes("utf-8"));
out.flush();
out.close();
}
Aggregations