springboot webflux 异常处理(WebExceptionHandler)


springboot webflux 异常处理(WebExceptionHandler)

 

 

*************************

相关类及接口

 

WebExceptionHandler

public interface WebExceptionHandler {
    Mono<Void> handle(ServerWebExchange var1, Throwable var2);
}

 

ErrorWebExceptionHandler

@FunctionalInterface
public interface ErrorWebExceptionHandler extends WebExceptionHandler {
}

 

AbstractErrorWebExceptionHandler

public abstract class AbstractErrorWebExceptionHandler implements ErrorWebExceptionHandler, InitializingBean {
    private static final Set<String> DISCONNECTED_CLIENT_EXCEPTIONS;
    private static final Log logger;
    private final ApplicationContext applicationContext;
    private final ErrorAttributes errorAttributes;
    private final ResourceProperties resourceProperties;
    private final TemplateAvailabilityProviders templateAvailabilityProviders;
    private List<HttpMessageReader<?>> messageReaders = Collections.emptyList();
    private List<HttpMessageWriter<?>> messageWriters = Collections.emptyList();
    private List<ViewResolver> viewResolvers = Collections.emptyList();

    public AbstractErrorWebExceptionHandler(ErrorAttributes errorAttributes, ResourceProperties resourceProperties, ApplicationContext applicationContext) {
        Assert.notNull(errorAttributes, "ErrorAttributes must not be null");
        Assert.notNull(resourceProperties, "ResourceProperties must not be null");
        Assert.notNull(applicationContext, "ApplicationContext must not be null");
        this.errorAttributes = errorAttributes;
        this.resourceProperties = resourceProperties;
        this.applicationContext = applicationContext;
        this.templateAvailabilityProviders = new TemplateAvailabilityProviders(applicationContext);
    }

    public void setMessageWriters(List<HttpMessageWriter<?>> messageWriters) {
        Assert.notNull(messageWriters, "'messageWriters' must not be null");
        this.messageWriters = messageWriters;
    }

    public void setMessageReaders(List<HttpMessageReader<?>> messageReaders) {
        Assert.notNull(messageReaders, "'messageReaders' must not be null");
        this.messageReaders = messageReaders;
    }

    public void setViewResolvers(List<ViewResolver> viewResolvers) {
        this.viewResolvers = viewResolvers;
    }

    /** @deprecated */
    @Deprecated
    protected Map<String, Object> getErrorAttributes(ServerRequest request, boolean includeStackTrace) {
        return this.getErrorAttributes(request, includeStackTrace ? ErrorAttributeOptions.of(new Include[]{Include.STACK_TRACE}) : ErrorAttributeOptions.defaults());
    }

    protected Map<String, Object> getErrorAttributes(ServerRequest request, ErrorAttributeOptions options) {
        return this.errorAttributes.getErrorAttributes(request, options);
    }

    protected Throwable getError(ServerRequest request) {
        return this.errorAttributes.getError(request);
    }

    protected boolean isTraceEnabled(ServerRequest request) {
        return this.getBooleanParameter(request, "trace");
    }

    protected boolean isMessageEnabled(ServerRequest request) {
        return this.getBooleanParameter(request, "message");
    }

    protected boolean isBindingErrorsEnabled(ServerRequest request) {
        return this.getBooleanParameter(request, "errors");
    }

    private boolean getBooleanParameter(ServerRequest request, String parameterName) {
        String parameter = (String)request.queryParam(parameterName
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值