# WebDev code 400

**URL:** <https://forum.inductiveautomation.com/t/webdev-code-400/73120>\
**Category:** Ignition\
**Created:** [May 1, 2023, 9:49pm UTC](https://forum.inductiveautomation.com/t/webdev-code-400/73120 "2023-05-01T21:49:31Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![CTavakoli](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@CTavakoli](https://forum.inductiveautomation.com/u/CTavakoli)\
**Post date:** [May 1, 2023, 9:49pm UTC](https://forum.inductiveautomation.com/t/webdev-code-400/73120/1 "2023-05-01T21:49:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 1, 2023, 9:51pm UTC](https://forum.inductiveautomation.com/t/webdev-code-400/73120/2 "2023-05-01T21:51:27Z")

</div>

Something like:

```auto
request['servletResponse'].sendError(400)

```

---

<div class="post-metadata">

**Author:** ![CTavakoli](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@CTavakoli](https://forum.inductiveautomation.com/u/CTavakoli)\
**Post date:** [May 1, 2023, 9:56pm UTC](https://forum.inductiveautomation.com/t/webdev-code-400/73120/3 "2023-05-01T21:56:53Z")

</div>

> [@Kevin.Herron](#):
>
> `request['servletResponse'].sendError(400)`

Thanks for an amazingly prompt reply

---

<div class="post-metadata">

**Author:** ![CTavakoli](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@CTavakoli](https://forum.inductiveautomation.com/u/CTavakoli)\
**Post date:** [May 2, 2023, 8:35pm UTC](https://forum.inductiveautomation.com/t/webdev-code-400/73120/4 "2023-05-02T20:35:47Z")

</div>

Do I need to close the stream too?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 2, 2023, 8:41pm UTC](https://forum.inductiveautomation.com/t/webdev-code-400/73120/5 "2023-05-02T20:41:18Z")

</div>

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.**

---

<div class="post-metadata">

**Author:** ![CTavakoli](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@CTavakoli](https://forum.inductiveautomation.com/u/CTavakoli)\
**Post date:** [May 2, 2023, 8:48pm UTC](https://forum.inductiveautomation.com/t/webdev-code-400/73120/6 "2023-05-02T20:48:25Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [May 2, 2023, 9:13pm UTC](https://forum.inductiveautomation.com/t/webdev-code-400/73120/7 "2023-05-02T21:13:34Z")

</div>

[Docs say](https://docs.oracle.com/javaee/7/api/javax/servlet/http/HttpServletResponse.html#sendError-int-java.lang.String-) 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.

---

<div class="post-metadata">

**Author:** ![CTavakoli](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@CTavakoli](https://forum.inductiveautomation.com/u/CTavakoli)\
**Post date:** [May 2, 2023, 10:18pm UTC](https://forum.inductiveautomation.com/t/webdev-code-400/73120/8 "2023-05-02T22:18:36Z")

</div>

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:

```auto
request['servletResponse'].setStatus(400)
request['servletResponse'].getWriter().print("blah blah")

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 2, 2023, 10:40pm UTC](https://forum.inductiveautomation.com/t/webdev-code-400/73120/9 "2023-05-02T22:40:19Z")

</div>

> [@Kevin.Herron](#):
>
> After using this method, the response should be considered to be committed and should not be written to.

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