Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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.