Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Spring with Hibernate User Messages in Spring Capturing Form Validation Errors

Andrey Serebryanskiy
Andrey Serebryanskiy
5,756 Points

How can I change a status code if new Category wasn't added?

Hey!

If we do not allow user to add a category because of invalid input, shouldn't we provide a HTTP status code that informs user about fail? How can we do it?

1 Answer

Ryan Wittrup
Ryan Wittrup
9,156 Points

Status codes are part of the HTTP response cycle - they are a part of a response to a request.

Thinking of a status code that way, if you do not navigate between pages, no response would be made. If the validation on the front end catches the error, you wouldn't need to worry about the response because the request was never sent.

If the server DOES catch a bad form, often the handle is a redirect which would come with the standard 3XX codes and a flash message of some kind is used to communicate the error.

In general, status codes are meant to describe the http request itself and not the payload. If you look over the list of all possible status codes, I think you'll see what I mean.