@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);
    }
@Test
    public void getErrorAttributes() {
        doNothing().when(loggerSpy).error(anyString());
        ServerWebExchange webExchange = MockServerWebExchange.from(MockServerHttpRequest.get("http://localhost:8080/favicon.ico"));
        NullPointerException nullPointerException = new NullPointerException("nullPointerException");
        Mono<Void> response = globalErrorHandler.handle(webExchange, nullPointerException);
        assertNotNull(response);
        assertNotNull(globalErrorHandler.handle(webExchange, new ResponseStatusException(HttpStatus.BAD_REQUEST)));
    }