0

In my controller I have a ethod annotated by GetMapping and I want to validate the path variable. I tested the @max and @min. they were ok. but the thing is when I want to check when no path variable is not passed, I get 404 error code. meaning that i want to test the case like:

http://localhost:9090/api/mancala-game/last-state/

where there is nothing after the last /.

I want to get the exception in my ExceptionHandler class.

any ideas? thank you

1

3 Answers 3

0

You should send path variable , in the url it self otherwise you will throw 404 error . when your are not sending path variable it will be a different API: in your case : http://localhost:9090/api/mancala-game/last-state/ and this url is not pointing to any handling method in your controller, So you will get 404 error.

Sign up to request clarification or add additional context in comments.

Comments

0

I think http://localhost:9090/api/mancala-game/last-state/ and

http://localhost:9090/api/mancala-game/last-state/{key} is two api.

you can create /last-state and /last-state/{key}

Comments

0

What you want to do is add a wildcard ** at the end of the REST endpoint api/mancala-game/last-state/ at the place where you call the antMatchers() method for this REST endpoint. For example:

.authorizeRequests().antMatchers(HttpMethod.GET, "api/mancala-game/last-state/**").permitAll() //Other antMatchers after this..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.