WebDev code 400

How should I force WebDev to respond with a code 400 ?

Something like:

request['servletResponse'].sendError(400)
2 Likes

Thanks for an amazingly prompt reply

Do I need to close the stream too?

Hmm, I don't think so, but the docs aren't explicit.

It sounds like not:

Sends an error response to the client using the specified status code and clears the buffer. The server will preserve cookies and may clear or update any headers needed to serve the error page as a valid response. If an error-page declaration has been made for the web application corresponding to the status code passed in, it will be served back the error page

If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.

1 Like

Thanks. Also, if I use an unassigned code (e.g. 419), I see that I can include a message, but have trouble parsing the message on the client side, any code snippet, is appreciated.

Docs say that when you include a message it returns some kind of HTML error page... you'll just have to figure out how to deal with that in your client I guess.

It appears that WebDev is ignoring the message and overrides it with some default. Would be great if you could please confirm if that is the case. The client is requiring that I send a custom message and specify why do I fail their request. For now this worked for me:

request['servletResponse'].setStatus(400)
request['servletResponse'].getWriter().print("blah blah")
1 Like

Flip those two lines around; write the output then set the status.

1 Like