Skip to content

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

@spring-projects-issues

Description

@spring-projects-issues

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

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions