-
Notifications
You must be signed in to change notification settings - Fork 766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix error-page for POST,PUT, etc. #1498
base: master
Are you sure you want to change the base?
Changes from all commits
a8eb8bb
6fc1e4c
8f228e4
e2d1824
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.mitre.openid.connect; | ||
|
||
import javax.servlet.RequestDispatcher; | ||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.security.oauth2.common.exceptions.OAuth2Exception; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
@Controller | ||
public class ErrorController { | ||
|
||
private static final Logger logger = LoggerFactory.getLogger(ErrorController.class); | ||
|
||
@RequestMapping("/error") | ||
public String handle(HttpServletRequest req) { | ||
Throwable errorException = (Throwable) req.getAttribute(RequestDispatcher.ERROR_EXCEPTION); | ||
String message = (String) req.getAttribute(RequestDispatcher.ERROR_MESSAGE); | ||
String requestUri = (String) req.getAttribute(RequestDispatcher.ERROR_REQUEST_URI); | ||
|
||
logger.error("request {} failed with {}", requestUri, message); | ||
logger.error("exception", errorException); | ||
|
||
processError(req); | ||
return "/error-view"; | ||
} | ||
|
||
private void processError(HttpServletRequest request) { | ||
if (request.getAttribute("error") instanceof OAuth2Exception) { | ||
request.setAttribute("errorCode", ((OAuth2Exception)request.getAttribute("error")).getOAuth2ErrorCode()); | ||
request.setAttribute("message", ((OAuth2Exception)request.getAttribute("error")).getMessage()); | ||
} else if (request.getAttribute(RequestDispatcher.ERROR_EXCEPTION) != null) { | ||
Throwable t = (Throwable)request.getAttribute(RequestDispatcher.ERROR_EXCEPTION); | ||
request.setAttribute("errorCode", t.getClass().getSimpleName() + " (" + request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE) + ")"); | ||
request.setAttribute("message", t.getMessage()); | ||
} else if (request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE) != null) { | ||
Integer code = (Integer)request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE); | ||
HttpStatus status = HttpStatus.valueOf(code); | ||
request.setAttribute("errorCode", status.toString() + " " + status.getReasonPhrase()); | ||
request.setAttribute("message", request.getAttribute(RequestDispatcher.ERROR_MESSAGE)); | ||
} else { | ||
request.setAttribute("errorCode", "Server error"); | ||
request.setAttribute("message", "See the logs for details"); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -404,8 +404,8 @@ | |
</dependency> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>servlet-api</artifactId> | ||
<version>2.5</version> | ||
<artifactId>javax.servlet-api</artifactId> | ||
<version>3.0.1</version> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there any other changes that updating the servlet version would bring to the underlying project? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this gives the static defines like RequestDispatcher.ERROR_MESSAGE as web.xml uses 3.0 syntax already. |
||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
|
@@ -644,7 +644,7 @@ | |
</dependency> | ||
<dependency> | ||
<groupId>javax.servlet</groupId> | ||
<artifactId>servlet-api</artifactId> | ||
<artifactId>javax.servlet-api</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>javax.servlet.jsp</groupId> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we still map this to
/error
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I'm not sure this is possbile without breaking things. Some other jsp pages directly redirect/forwards to /error when changing the above "catch all" error location these wont get catch. Or do I misunderstand. Let me ask the otherway around:
another thing that should be done is to move the controller logic from error.jsp in the ErrorController.