Node server crashes in parsing JSON

前端 未结 1 1129
自闭症患者
自闭症患者 2021-01-21 15:29

Looks like my node server dies in parseJSON. Looked at the logs and the last message was \"before parse\" and it never printed \"after parse\". What\'s strange is t

相关标签:
1条回答
  • 2021-01-21 16:10

    If your code crashes in parseJSON then I would try:

    try {
      logger.print("before parse")
      parseJSON(data)
      logger.print("after parse")
    } catch (e) {
      console.log(e);
    }
    

    It is strange because your function should catch the exception but this would show what happens. I would also add:

    console.log(data.length);
    

    to see the size of the data.

    Also I wrote a module tryjson that parses JSON without throwing exceptions. You can try using it but if your function crashes then maybe my module would not handle it either. Though I'd love to know what actually happens.

    0 讨论(0)
提交回复
热议问题