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 awaiting the request because I am sending two other requests with the classify request in parallel, but am awaiting 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?
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.