#promise rejections

1 messages · Page 1 of 1 (latest)

elfin panther
#

no, I mean how do you handle promises within your run method?

#

do you await or return them?

verbal stream
#

return

#

and await

elfin panther
#

if you await or return all of them the handler should be able to catch them

verbal stream
#

ok, so return await i.editReply() isnt an issue?

elfin panther
#

it's not

verbal stream
#

for other promises it looks like this

#
        const player = await getPlayer(tag).catch(e => {
            if (e?.response?.status === 404) throw '**Player not found.**';

            throw e?.response?.statusText || 'Unexpected Error.';
        });
#

and then it is caught in the code above this ^

elfin panther
#

yes, that will be catched in the outer try catch too

verbal stream
#

hmm

#

discord isnt giving me any useful errors and its making this difficult to figure out

#

just Unknown Interaction and then it crashes

elfin panther
#

you can listen to "unhandledRejection" on process

verbal stream
#

no issues in development though, cant replicate it

verbal stream
#

so just log it everytime theres an unhandled rejection?

elfin panther
#

you can do that, though you should follow the stack trace and handle them where they are thrown initially

verbal stream
#

gotcha, what exactly would that look like?

process.on('unhandledRejection', e => {
    //?
});
#

just console.error(e)?

elfin panther
#

sure