Kianoosh
04/29/2019, 9:42 PMmusics.map(async (music) => {
let isMusicExists = await context.prisma.$exists.musicDirectory({
AND: [
{
directoryId,
musics_some: {
trackId: music.trackId,
trackService: music.trackService
}
}
]
});
if (isMusicExists){
throw new Error('This music is already added in this place!')
}
});
this piece of code is in middle of my revolver, What i expect after receiving duplicate record is throwing an error and stop the execution furthermore but what i get in console is:
(node:11309) UnhandledPromiseRejectionWarning: Error: This music is already added in this place!
at musics.map (/home/kianoosh/MyApp/resolvers/Mutation.js:384:23)
at processTicksAndRejections (internal/process/task_queues.js:86:5)
(node:11309) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
I tried to use catch but it didn't make any difference after all the error is just printing in console and doesn't stop anything.carlo
04/29/2019, 9:46 PMawait Promise.all(musics.map(async (music) => {
Jared
04/29/2019, 9:46 PMJared
04/29/2019, 9:46 PMfor ... in
Jared
04/29/2019, 9:48 PMfor in
will make them fire one after the other. Promise.all will fire them all at the same time.Kianoosh
04/29/2019, 10:10 PMKianoosh
04/29/2019, 10:11 PMfor in
is more optimized than Promise.all
?