error handling
Hi, i dont know how to handling error that say in this link line messaging api ref, it said
The following JSON data is returned in the response body when an error occurs.
so, i try using this
return client.replyMessage(event.replyToken, {
type: "text",
text: "" //im leaving this empty for testing
});
i try to get this response (like in api reference)
{
"message":"The request body has 2 error(s)",
"details":[
{
"message":"May not be empty",
"property":"messages[0].text"
},
{
"message":"Must be one of the following values: [text, image, video, audio, location, sticker, template, imagemap]",
"property":"messages[1].type"
}
]
}
but i dont know how
this is my full script server.js
TIA
Hello there,
I saw your server.js and I think the error will go into line 19~21.
Since error response will be in error statusCode, you can handle it by client.replyMessage().catch.
yeah, it show error status code 400, bad request.
however i though there is can get response like this
{ "message":"The request body has 2 error(s)", "details":[ { "message":"May not be empty", "property":"messages[0].text" }, { "message":"Must be one of the following values: [text, image, video, audio, location, sticker, template, imagemap]", "property":"messages[1].type" } ] }
but i think its not possible on nodejs. only shell method (curl)
any built in method to know what cause of error? like, more spesific error?
400 error means the parameter you passed is not correct.
You should correct it but not handle it.
The cause of error is in details field.
And by the way, the type of this kind of Error should be HTTPError. You can also handle it as
error instanceof HTTPError
i see, thanks for fast reply!