Skip to content

SPR-14818: Added MissingHeaderException type #1653

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

Closed
wants to merge 1 commit into from
Closed

SPR-14818: Added MissingHeaderException type #1653

wants to merge 1 commit into from

Conversation

pebo
Copy link

@pebo pebo commented Jan 26, 2018

No description provided.

@pivotal-issuemaster
Copy link

@pebo Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@pivotal-issuemaster
Copy link

@pebo Thank you for signing the Contributor License Agreement!

* limitations under the License.
*/

package org.springframework.web.bind;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the right place to sit the exception?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't know but the package contains similar exceptions like MissingPathVariableException

@@ -82,8 +83,7 @@ protected Object resolveName(String name, MethodParameter parameter, NativeWebRe

@Override
protected void handleMissingValue(String name, MethodParameter parameter) throws ServletRequestBindingException {
throw new ServletRequestBindingException("Missing request header '" + name +
"' for method parameter of type " + parameter.getNestedParameterType().getSimpleName());
throw new MissingHeaderException(name, parameter);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my humble opinion, this is fine as it used to be, as including a new class is adding also complexity. So, what are the advantages adding this exception class just to manage this one? But this is my opinion!!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with the added complexity. I found https://jira.spring.io/browse/SPR-14818 when trying to return a custom error message for missing headers in the ResponseEntityExceptionHandler#handleServletRequestBindingException callback. Now my workaround is to check the message text of the ServletRequestBindingException for the text "Missing request header".. is there a better way to implement the ResponseEntityExceptionHandler callback?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see what you mean, they throw more specific exception, more meaningful. I guess it is alright, let see if someone else give their opinion. So far, I don't have anything better from the top of my head!! ;) good work!

@baynezy
Copy link

baynezy commented Feb 3, 2018

I don't see any issue adding the new exception. It properly extends the existing exception so is backwards compatible. The code is now more descriptive of the issue.

This fixes a challenge we have, which we have had to solve with string parsing so this is a great PR in my opinion. Please approve

@rstoyanchev
Copy link
Contributor

@baynezy the PR is linked to an issue where you'll see that Juergen already commented.

@luyaor
Copy link

luyaor commented Jul 14, 2018

Dear pebo(@pebo) & fmcejudo(@fmcejudo),

We are working on identifying redundant development and duplicated pull requests. We have found there is a pull request: #1218 which might be a potentially duplicate to this one. We would really appreciate if you could help us to validate and give us feedback.

Thank you very much for your time!

@jhoeller
Copy link
Contributor

Resolved as part of a wider revision now, introducing MissingRequestHeaderException as well as MissingRequestCookieException and MissingMatrixVariableException for 5.1 RC1. Thanks for the pull request, in any case!

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.

7 participants