Skip to content
Advertisement

Catch block not working in node fetch

Trying to learn, Javascript. Pardon if this is really a basic thin i am missing.

I am trying to run node-fetch to a wrong url, and i expect that it should be catched and log my appropriate message. However when i run this file through node, it gives me uncatched error

JavaScript

Advertisement

Answer

Its this part that is uncatched:

JavaScript

Therefore attach a catch handler to it:

JavaScript

or simply return it so that it is catched by the other handler:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement