Skip to content

SPR-14818 - Implement MissingServletRequestAttributeException - #1839

Closed
carterkozak wants to merge 1 commit into
spring-projects:masterfrom
carterkozak:missing_request_attribute_exception_type
Closed

carterkozak wants to merge 1 commit into
spring-projects:masterfrom
carterkozak:missing_request_attribute_exception_type

Conversation

@carterkozak

Copy link
Copy Markdown
Contributor

Provides a way to programatically detect when specific attributes
are not provided.

@snicoll
snicoll requested a review from rstoyanchev May 28, 2018 07:28
@rstoyanchev

Copy link
Copy Markdown
Contributor

The same point can be made for Session attributes, or even more broadly. This would normally require a ticket (as per our guidelines) but there is one already SPR-14818 where this belongs.

@rstoyanchev
rstoyanchev requested a review from jhoeller May 29, 2018 14:11
@carterkozak carterkozak changed the title Implement MissingServletRequestAttributeException SPR-14818: Implement MissingServletRequestAttributeException May 29, 2018
@carterkozak carterkozak changed the title SPR-14818: Implement MissingServletRequestAttributeException SPR-14818 - Implement MissingServletRequestAttributeException May 29, 2018
@carterkozak

Copy link
Copy Markdown
Contributor Author

Thanks for the link @rstoyanchev! I'll implement this for session attributes as well.

Implemented RequestAttributeMethodArgumentResolverTests and
MissingServletRequestAttributeException for missing request
and session attributes respectively.

Provides a way to programatically detect when specific attributes
are not provided.
@carterkozak
carterkozak force-pushed the missing_request_attribute_exception_type branch from 86e8690 to fff8a69 Compare May 29, 2018 15:34
@rstoyanchev

Copy link
Copy Markdown
Contributor

I'm not sure if the solution will follow the route of one exception for every kind of input. As indicated under SPR-14818 there are a quite a few of those. Perhaps some sort of NameValueBindingException could address the need more generally.

@carterkozak

Copy link
Copy Markdown
Contributor Author

That makes sense. I would like to have a mechanism to differentiate missing headers from missing request attributes, for example. We could accomplish this with simple interface and enum implementation, though in that case the complexity is similar to implementing a custom exception type for each resolver.

@jhoeller

Copy link
Copy Markdown
Contributor

Since missing request attributes or session attributes are effectively state assertions within the application, I don't see a need for a dedicated exception type here, unless a compelling case can be made that the name of the attribute needs to be programmatically processed.

The current resolution of SPR-14818 differentiates all remaining request-specific exceptions (request header, cookie, matrix variable) through specific exception types, allowing for HTTP status codes, so at least these attribute assertions here are now quite isolated in rest-of-ServletRequestBindingException which effectively indicate server-internal assertion errors.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants