@Override
    @NonNull
    public Mono<Void> handle(@NonNull final ServerWebExchange exchange, @NonNull final Throwable throwable) {
        LOG.error("handle error: {} formatError:{} throwable:", exchange.getLogPrefix(), formatError(throwable, exchange.getRequest()), throwable);
        HttpStatusCode httpStatusCode;
        Object errorResult;
        String errorMsg = "";
        if (throwable instanceof IllegalArgumentException) {
            httpStatusCode = HttpStatus.BAD_REQUEST;
            errorResult = ShenyuResultWrap.error(exchange, httpStatusCode.value(), throwable.getMessage(), null);
            errorMsg = throwable.getMessage();
        } else if (throwable instanceof ResponseStatusException) {
            httpStatusCode = ((ResponseStatusException) throwable).getStatusCode();
            HttpStatus httpStatus = (HttpStatus) httpStatusCode;
            String errMsg = StringUtils.hasLength(((ResponseStatusException) throwable).getReason()) ? ((ResponseStatusException) throwable).getReason() : httpStatus.getReasonPhrase();
            errorResult = ShenyuResultWrap.error(exchange, httpStatusCode.value(), errMsg, null);
            errorMsg = errMsg;
        } else {
            httpStatusCode = HttpStatus.INTERNAL_SERVER_ERROR;
            HttpStatus httpStatus = (HttpStatus) httpStatusCode;
            errorResult = ShenyuResultWrap.error(exchange, httpStatusCode.value(), httpStatus.getReasonPhrase(), null);
            errorMsg = httpStatus.getReasonPhrase();
        }
        exchange.getResponse().setStatusCode(httpStatusCode);
        Map<String, String> labels = new HashMap<>(8);
        labels.put("global", "error");
        labels.put("component", "gateway");
        AlarmSender.alarmMediumCritical("ShenYu-Gateway-Global-Error", errorMsg, labels);
        return WebFluxResultUtils.result(exchange, errorResult);
    }
handler error.

@param exchange  the exchange
@param throwable the throwable
@return error result
shenyu-web/src/main/java/org/apache/shenyu/web/handler/GlobalErrorHandler.java