Skip to content
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

Provide empty Model to @ExceptionHandler methods [SPR-13546] #18122

Closed
spring-projects-issues opened this issue Oct 7, 2015 · 5 comments
Closed
Assignees
Labels
in: web type: enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Oct 7, 2015

Kazuki Shimizu opened SPR-13546 and commented

Currently, when i want to add a object into the Model, i implements as returning the ModelAndView object from @ExceptionHandler method as follow.

@ExceptionHandler
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public ModelAndView handleException(Exception e) {
	ModelAndView mav = new ModelAndView("error/systemError");
	mav.getModelMap().addAttribute("message", e.getMessage());
	return mav;
}

I want to use the Model at @ExceptionHandler method argument instead of ModelAndView by default as follow.

@ExceptionHandler
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public String handleException(Exception e, Model model) {
	model.addAttribute("message", e.getMessage());
	return "error/systemError";
}

How do think ?
I submit PR at later.


Affects: 4.2.1

Referenced from: pull request #883, and commits 4391b29, 44b76d3

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 7, 2015

Kazuki Shimizu commented

I've submit the PR.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 7, 2015

Juergen Hoeller commented

Good point, that's a gap that's easy enough to close.
Addressed for 4.2.2 now, in a slightly revised fashion.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 7, 2015

Kazuki Shimizu commented

Hi Juergen Hoeller, thanks for polishing and merging.
I'm happy :)

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 9, 2015

Rossen Stoyanchev commented

This makes sense as long as there is no expectation for this to be the same model the controller method would have had access to. Clearly not the request here but worth updating the Javadoc for @ExceptionHandler.

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Oct 9, 2015

Sam Brannen commented

I agree with Rossen. If it's not clearly documented (at least in the Javadoc but preferably also in the reference manual), people will certainly make the wrong assumption about which Model it is and wonder why the model supplied to an exception handler is empty.

@spring-projects-issues spring-projects-issues added type: enhancement in: web labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 4.2.2 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants