# Handling HTTPRequest Error

**URL:** <https://discourse.nodered.org/t/handling-httprequest-error/85918>\
**Category:** General\
**Created:** [26 February 2024 11:25 UTC](https://discourse.nodered.org/t/handling-httprequest-error/85918 "2024-02-26T11:25:52Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![shershah](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@shershah](https://discourse.nodered.org/u/shershah)\
**Post date:** [26 February 2024 11:25 UTC](https://discourse.nodered.org/t/handling-httprequest-error/85918/1 "2024-02-26T11:25:52Z")

</div>

Dear All,

Currently I am hitting http request to get the response. When API is down , I am not able to handle the exception. I am getting "JSON parse error".

Catch block is not triggering , nor I am getting any http outpout as I have switch node to check the statusCode.

Please help, Thanks in advance.

Regards,  
Shershah

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [26 February 2024 12:53 UTC](https://discourse.nodered.org/t/handling-httprequest-error/85918/2 "2024-02-26T12:53:37Z")

</div>

Output a utf string, then check msg.statusCode in the response message and only allow the ones you want to pass, i.e 200, then pass through a json node.

---

<div class="post-metadata">

**Author:** ![shershah](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@shershah](https://discourse.nodered.org/u/shershah)\
**Post date:** [26 February 2024 15:44 UTC](https://discourse.nodered.org/t/handling-httprequest-error/85918/3 "2024-02-26T15:44:13Z")

</div>

I tried and still getting the "JSON parse error"

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [26 February 2024 15:46 UTC](https://discourse.nodered.org/t/handling-httprequest-error/85918/4 "2024-02-26T15:46:07Z")

</div>

What data are you getting? Has the error moved to the JSON node? Use a debug to see what is being passed to the JSON node. My guess is your getting html not JSON.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [26 February 2024 16:05 UTC](https://discourse.nodered.org/t/handling-httprequest-error/85918/5 "2024-02-26T16:05:00Z")

</div>

To add to Steve's questions, what are the statusCodes received when working and when down?  
How is the catch node set up?  
Set all debugs nodes to complete message object  
How are you checking for Statuscodes?

You need to supply info so we can diagnose.

---

<div class="post-metadata">

**Author:** ![shershah](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@shershah](https://discourse.nodered.org/u/shershah)\
**Post date:** [26 February 2024 16:16 UTC](https://discourse.nodered.org/t/handling-httprequest-error/85918/6 "2024-02-26T16:16:12Z")

</div>

@Steve-Mcl @E1cid I am getting below data in payload and 404 as statusCode

```auto
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Error</title>
</head>
<body>
<pre>Cannot POST /post/data</pre>
</body>
</html>

statusCode : 404

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [26 February 2024 17:26 UTC](https://discourse.nodered.org/t/handling-httprequest-error/85918/7 "2024-02-26T17:26:50Z")

</div>

> [@shershah](#):
>
> `statusCode : 404`

So what is the problem then? Use that to indicate the error. Obviously do not pass messages with error to the JSON node.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [26 February 2024 17:56 UTC](https://discourse.nodered.org/t/handling-httprequest-error/85918/8 "2024-02-26T17:56:00Z")

</div>

I thought you had a basic understanding of node-red standard nodes. You may get some benefit from watching these [essentials videos](https://m.youtube.com/watch?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6&v=ksGeUD26Mw0&embeds_referring_euri=https%3A%2F%2Fnodered.org%2F&source_ve_path=OTY3MTQ&feature=emb_imp_woyt)

To the issue.  
Add a switch node between the http and the JSON nodes. set property to `statusCode` and the rule to `== 200` the 200 is a number not a string.

---

<div class="post-metadata">

**Author:** ![shershah](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@shershah](https://discourse.nodered.org/u/shershah)\
**Post date:** [27 February 2024 05:58 UTC](https://discourse.nodered.org/t/handling-httprequest-error/85918/9 "2024-02-27T05:58:49Z")

</div>

I am doing the same, output of httprequest is linked with switch node. but no output is coming, request is not flowing to switch node and getting an exception "JSPN parse error"

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [27 February 2024 07:27 UTC](https://discourse.nodered.org/t/handling-httprequest-error/85918/10 "2024-02-27T07:27:42Z")

</div>

Please export your flow and paste here  
[How to import/export a flow](https://nodered.org/docs/user-guide/editor/workspace/import-export)

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote `````)

````auto
``` 
   code goes here 
```

````

You can edit and correct your post by clicking the pencil ✏ icon.

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [27 May 2024 07:28 UTC](https://discourse.nodered.org/t/handling-httprequest-error/85918/11 "2024-05-27T07:28:04Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
