-
Notifications
You must be signed in to change notification settings - Fork 62
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Issue Description
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).
Rationale / Further Reading
Example
import AppleAuth from 'apple-auth';
declare var auth: AppleAuth;
try {
await auth.accessToken(code);
} catch (error) {
typeof error; // Actual: "string" here. Doesn't have any stack trace or `message` property from a standard Error.
}
try {
null.x;
} catch (error) {
error instanceof Error; // 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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working
