softdevteam / mattermost-github-integration

GitHub integration for Mattermost
Other
79 stars 50 forks source link

How to handle 400 bad request in mattermost while using node red #26

Closed chaitanya9249 closed 7 years ago

chaitanya9249 commented 7 years ago

In node red,I am calling an api in one function by http request node.That api generated response

"400 (bad request) error".I am passing that response as attachment format into matter-most. Due to the 400 response I am getting output in mattermost as JSON error.

Please help me how to over come this and how handle 400 error in mattermost in NODE-RED

ptersilie commented 7 years ago

I'm not familiar with node-red. Could you please post some more details please?

chaitanya9249 commented 7 years ago

Here I am attaching my node-red flow 1

**In "PoListApi" I am calling an api as like below:

var mVendorNumber = msg.req.query.mVendor var developerMsg;

msg.headers = { "appToken": 'ms8l0TAFoWAtw9ot9HjjbIMBZlNX' }

if (mVendorNumber.length !== 0) { msg.payload = { "search": { "mVendorNumber": mVendorNumber } } msg.url = "https://qa1.api.hs.homedepot.com/iconx/v1/poworklist/list" } else { msg.payload = "No Results found"; } node.send(msg);**

It gives response as 400 (bad request) error.My intention is I want to catch and handle that error in httprequest node and display as message in attachment format in mattermost app.

Here is my attchment format

{ "_attachment": { "template": { "type": "generic", "content": [{ "h5": "ICONX_DETAILS" }, { "title": { "text": "ICONX_DETAILS", "link": "www.google.co.in" } }, { "table": { "headers": [ "PO LIST" ], "rows": [

                    ]
                }
            }
        ]
    }
}

}

Could you please help me how to catch http errors in http request node in node red.