Skip to content
Advertisement

Unhandled promise rejection, even though I’m pretty sure I’ve handled them all

I’ve written a node app that fetches data from an API, using multiple endpoints. I am also using proxies to do this.

I’m currently using socks-proxy-agent to create a https agent for my axios instances to use the proxy.

Here is the class that does all of this:

JavaScript

However, if there’s an issue with a proxy, I get unhandled promise rejections like this that seem to be coming from the socket:

JavaScript

However, I’m pretty sure I’ve handled everything. I even have a try/catch block around my await calls.

Advertisement

Answer

As I’m looking at your code this api call this.client.post("https://auth.riotgames.com/userinfo") doesn’t have catch function. By separating each one of your api calls in different functions and returning them, your code becomes much cleaner and finding these errors becomes easier.

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