001/* 002 * Copyright 2012-2017 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.servlet.error; 018 019import java.util.Map; 020 021import org.springframework.web.bind.annotation.ResponseBody; 022import org.springframework.web.context.request.WebRequest; 023import org.springframework.web.servlet.ModelAndView; 024 025/** 026 * Provides access to error attributes which can be logged or presented to the user. 027 * 028 * @author Phillip Webb 029 * @since 2.0.0 030 * @see DefaultErrorAttributes 031 */ 032public interface ErrorAttributes { 033 034 /** 035 * Returns a {@link Map} of the error attributes. The map can be used as the model of 036 * an error page {@link ModelAndView}, or returned as a {@link ResponseBody}. 037 * @param webRequest 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(WebRequest webRequest, 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 webRequest the source request 048 * @return the {@link Exception} that caused the error or {@code null} 049 */ 050 Throwable getError(WebRequest webRequest); 051 052}