-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
admin.auth().createCustomToken() is not correctly returning a rejected promise #284
Comments
This is debatable. For example our JS client SDKs with promise returning APIs also throw synchronous errors when provided with invalid arguments. We aim to fail fast when you provide invalid types for arguments. I know there are other APIs that intentionally do this. Here is an example with the |
Gotcha, thanks for the context! Maybe I need to read up a bit more on promises and throw vs Promise.reject(), but shouldn't throwing still be caught by a subsequent My concern is that it makes the promise behavior feel a little unpredictable, but if it's determined it's 100% intentional, would it be possible to document the behavior? |
To add to what @bojeil-google mentioned, how certain types of errors are handled in JS is largely a matter of preference and style. The style the Admin SDK strives to adhere to is:
In that sense the |
Thanks, it's good to know that pattern - would be fantastic to have in the docs somewhere perhaps. Agreed that consistency is usually best above all, and appreciate that potentially being addressed down the road. Apologies again if this stems from me not fully understanding how promises work, and thank you in advance for taking any time out of your day to clarify. My confusion is that: createCustomToken()
.catch(() => { console.log('Never fires') }) is not working, whereas createCustomToken('userId', {})
.then(() => { throw new Error('This gets caught') }
.catch((error) => console.log('Fires', error)) does. Either way, it sounds like the behavior is potentially solved by never chaining |
@constancecchen I would also like to draw your attention to #285. Today,
|
Thanks, good to know. Excited for that PR, by the way! :) Thanks for implementing it! I'll modify my project to accommodate existing behavior since it's intentional. Also since it's intentional, consider this issue closed as wontfix, I suppose. I'll dig a bit more into promises some other time and try to get to the bottom of why a thrown error would skip being caught. |
Environment
Describe the problem
createCustomToken()
correctly returns chained.then()
resolved promises but not.catch()
rejected errors. Nothing inside a.catch()
block that immediately followscreateCustomToken()
fires at all - it's as if the promise just returns immediately without stopping (which no other Firebase promise that I've used so far has done).This is frustrating for my use case because I'm trying to throw my own custom error/exception and not Firebase's.
Relevant Code:
Steps to reproduce:
Never fires
never outputs into the server-side logs..createCustomToken()
in the code above with another admin function, such as.createUser()
(params deliberately left blank to invoke an error), or even a genericPromise.reject()
. You should now see the following JSON response:Never fires
is now being logged server-side, which means that the first/nested.catch()
is now actually being respected.I'm not an expert on promises or anything, so I'm not totally sure what the scenario for this is called (swallowed error?) - but it definitely doesn't seem like expected behavior for a promise to just ignore a
.catch()
block. I'd love for this to get fixed so I can handle.createCustomToken()
with my own error messaging instead of having to use Firebase's.The text was updated successfully, but these errors were encountered: