Spring mvc not showing correct http status -


in controller class, check if id correct, if not, controller should throw exception:

        if (!id.matches("blablabla")) {         throw new invalididexception();     } 

then in exception class, add annotation

@responsestatus(value= httpstatus.bad_request,reason="invalid id") public class invalididexception extends runtimeexception{ public invalididexception(){}  public invalididexception(string message) {super(message);} public invalididexception(throwable cause) {super(cause);} } 

so if id invalid, should throw http 400 error.(i @ error right clicking on webpage , inspect element, network) however, not sure why still shows http 404 if id invalid.

updated: seems if add 1 line of code inside throw exception, works. :

if (!id.matches("blablabla")) { response.senderror(400,"invalid id");         throw new invalididexception();     } 


Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo