You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Promise rejections in the source code are currently using (primitive) strings. For example:
This would make exception handling more cumbersome (because an additional type check is needed) and more difficult (all stack trace information is destroyed).
importAppleAuthfrom'apple-auth';declarevarauth: AppleAuth;try{awaitauth.accessToken(code);}catch(error){typeoferror;// Actual: "string" here. Doesn't have any stack trace or `message` property from a standard Error.}try{null.x;}catch(error){errorinstanceofError;// Expected: an instance of Error (or a subclass).}
Proposed Solution
All exceptions from Promise constructors should be instances of Error. Using the example of src/apple-auth.js from the above image:
reject(
- `AppleAuth Error - An error occurred while getting response from Apple's servers: - ${response}${responseData ? (" | " + responseData) : ""}`+ new Error(+ `AppleAuth Error - An error occurred while getting response from Apple's servers: + ${response}${responseData ? (" | " + responseData) : ""}`+ )
);
I am able to make a pull request for these changes.
The text was updated successfully, but these errors were encountered:
Issue Description
Promise
rejections in the source code are currently using (primitive)string
s. For example:This would make exception handling more cumbersome (because an additional type check is needed) and more difficult (all stack trace information is destroyed).
Rationale / Further Reading
no-throw-literal
ESLint ruleExample
Proposed Solution
All exceptions from
Promise
constructors should be instances ofError
. Using the example ofsrc/apple-auth.js
from the above image:I am able to make a pull request for these changes.
The text was updated successfully, but these errors were encountered: