Reputation: 47
While implementing a graphql resolver function, I ran into an UnhandledPromiseRejectionWarning
error. Am sending a request to classify some text and it's the classification that's throwing an error. I want to re-throw whatever error is thrown, but the error is not being caught in the catch block.
Am not await
ing the request because I am sending two other requests with the classify request in parallel, but am await
ing each request in a Promise.all function.
Here is the code:
createPost: async (
_,
{ fields: { media, text, location } }) => {
try {
const firstRequest = languageClient.classifyText({
document: {
content: text,
type: 'PLAIN_TEXT'
}
});
const secondRequest = // another request
const thirdRequest = // another request
const result = await Promise.all([firstRequest, secondRequest, thirdRequest]);
} catch(error) { throw error }
}
How do I handle the error properly?
Upvotes: 1
Views: 169
Reputation: 47
Stupid me, I wrapped the Promise.all
with an if statement, so it's not even running at all. That's the reason why am getting weird results. I just discovered this after 3 days. I'm so stupid.
Upvotes: 1