001/*
002 * Copyright 2012-2018 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.boot.web.reactive.error;
018
019import java.util.Map;
020
021import org.springframework.web.reactive.function.server.ServerRequest;
022import org.springframework.web.reactive.function.server.ServerResponse;
023import org.springframework.web.server.ServerWebExchange;
024
025/**
026 * Provides access to error attributes which can be logged or presented to the user.
027 *
028 * @author Brian Clozel
029 * @since 2.0
030 * @see DefaultErrorAttributes
031 */
032public interface ErrorAttributes {
033
034        /**
035         * Return a {@link Map} of the error attributes. The map can be used as the model of
036         * an error page, or returned as a {@link ServerResponse} body.
037         * @param request the source request
038         * @param includeStackTrace if stack trace elements should be included
039         * @return a map of error attributes
040         */
041        Map<String, Object> getErrorAttributes(ServerRequest request,
042                        boolean includeStackTrace);
043
044        /**
045         * Return the underlying cause of the error or {@code null} if the error cannot be
046         * extracted.
047         * @param request the source ServerRequest
048         * @return the {@link Exception} that caused the error or {@code null}
049         */
050        Throwable getError(ServerRequest request);
051
052        /**
053         * Store the given error information in the current {@link ServerWebExchange}.
054         * @param error the {@link Exception} that caused the error
055         * @param exchange the source exchange
056         */
057        void storeErrorInformation(Throwable error, ServerWebExchange exchange);
058
059}