Skip to content

Allow HTTP status exceptions to be easily thrown from Controllers [SPR-14895] #19461

@spring-projects-issues

Description

@spring-projects-issues

Norris Shelton opened SPR-14895 and commented

There is no way to throw exceptions out of the box. Developers must create exceptions for each HTTP status they want to throw, create exception handlers, etc. It would be much better if basic functionality was included. I created a ResourceException class (probably could have a better name for Spring), a generic controller advice (maybe call it something specific to the exception class). If they are included in the SpringFramework, it would be backwards compatible and it would be very easy to throw an exception. An example usage would be:

throw new ResourceException(HttpStatus.BAD_REQUEST, "Missing the user first name");


Affects: 4.3.4

Reference URL: http://stackoverflow.com/questions/16232833/how-to-respond-with-http-400-error-in-a-spring-mvc-responsebody-method-returnin/40518283#40518283

Attachments:

Issue Links:

2 votes, 6 watchers

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