line-bot-sdk-nodejs icon indicating copy to clipboard operation
line-bot-sdk-nodejs copied to clipboard

error handling

Open EriecTanijaya opened this issue 6 years ago • 6 comments

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

EriecTanijaya avatar Dec 10 '19 03:12 EriecTanijaya

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.

xingoxu avatar Dec 10 '19 04:12 xingoxu

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)

EriecTanijaya avatar Dec 10 '19 04:12 EriecTanijaya

any built in method to know what cause of error? like, more spesific error?

EriecTanijaya avatar Dec 10 '19 04:12 EriecTanijaya

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.

xingoxu avatar Dec 10 '19 04:12 xingoxu

And by the way, the type of this kind of Error should be HTTPError. You can also handle it as error instanceof HTTPError

xingoxu avatar Dec 10 '19 05:12 xingoxu

i see, thanks for fast reply!

EriecTanijaya avatar Dec 10 '19 05:12 EriecTanijaya