use of com.alibaba.csp.sentinel.slots.block.flow.FlowException in project flash-sale by ThoughtsBeta.
the class InternalExceptionHandler method handleConflict.
@ExceptionHandler(value = { Exception.class, RuntimeException.class })
protected ResponseEntity<Object> handleConflict(Exception ex, WebRequest request) {
ExceptionResponse exceptionResponse = new ExceptionResponse();
if (ex instanceof UndeclaredThrowableException) {
if (((UndeclaredThrowableException) ex).getUndeclaredThrowable() instanceof FlowException) {
exceptionResponse.setErrorCode(LIMIT_BLOCK.getCode());
exceptionResponse.setErrorMessage(LIMIT_BLOCK.getDesc());
}
} else {
exceptionResponse.setErrorCode(INTERNAL_ERROR.getCode());
exceptionResponse.setErrorMessage(INTERNAL_ERROR.getDesc());
}
logger.error("unknownError|未知错误|{}", ex.getClass());
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.APPLICATION_JSON);
return handleExceptionInternal(ex, JSON.toJSONString(exceptionResponse), httpHeaders, HttpStatus.INTERNAL_SERVER_ERROR, request);
}
use of com.alibaba.csp.sentinel.slots.block.flow.FlowException in project amusing-project by m-lvqingyu.
the class GatewayBlockExceptionHandler method handle.
@Override
public Mono<Void> handle(ServerWebExchange serverWebExchange, Throwable throwable) {
ServerHttpResponse response = serverWebExchange.getResponse();
setProps(response);
ServerHttpRequest request = serverWebExchange.getRequest();
String path = request.getURI().getPath();
// 限流
if (throwable instanceof FlowException) {
log.error("[gateway-sentinel]-request is flow, path:{}", path);
return responseWrite(response, ApiResult.result(CommCode.FLOW_ERROR));
}
// 熔断
if (throwable instanceof DegradeException) {
log.error("[gateway-sentinel]-request is degrade, path:{}", path);
return responseWrite(response, ApiResult.result(CommCode.DEGRADE_ERROR));
}
// 热点参数限流
if (throwable instanceof ParamFlowException) {
log.error("[gateway-sentinel]-request is paramFlow, path:{}", path);
return responseWrite(response, ApiResult.result(CommCode.PARAM_FLOW_ERROR));
}
// 系统保护规则
if (throwable instanceof SystemBlockException) {
log.error("[gateway-sentinel]-request is systemBlock, path:{}", path);
return responseWrite(response, ApiResult.result(CommCode.SYSTEM_BLOCK_ERROR));
}
// 授权规则
if (throwable instanceof AuthorityException) {
log.error("[gateway-sentinel]-request is authority, path:{}", path);
return responseWrite(response, ApiResult.result(CommCode.AUTHORITY_ERROR));
}
return responseWrite(response, ApiResult.result(CommCode.FREQUENT_OPERATION_EXCEPTION));
}
Aggregations