-
Notifications
You must be signed in to change notification settings - Fork 756
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't mutate error.type during minification (#2043)
* accept hardcoded type in StripeError constructor * Default to this.constructor.name when type is not provided * Add test project * Don't need eslint config
- Loading branch information
1 parent
800e45e
commit 7aaf448
Showing
6 changed files
with
133 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import {Stripe} from 'stripe'; | ||
import assert from 'assert'; | ||
|
||
// API key is null to trigger an authentication error | ||
const stripe = new Stripe(null, { | ||
host: process.env.STRIPE_MOCK_HOST || 'localhost', | ||
port: process.env.STRIPE_MOCK_PORT || 12111, | ||
protocol: 'http', | ||
}); | ||
|
||
try { | ||
throw new stripe.errors.StripeUnknownError({ | ||
charge: 'foo', | ||
unknown_prop: 'bar', | ||
}); | ||
} catch (e) { | ||
assert (e instanceof stripe.errors.StripeUnknownError); | ||
assert (e.type === 'StripeUnknownError'); | ||
} | ||
|
||
async function exampleFunction(args) { | ||
try { | ||
await stripe.paymentIntents.create(args); | ||
} catch (e) { | ||
assert (e instanceof stripe.errors.StripeAuthenticationError); | ||
assert (e.type === 'StripeAuthenticationError'); | ||
} | ||
} | ||
|
||
exampleFunction({ | ||
// The required parameter currency is missing | ||
amount: 2000, | ||
confirm: true, | ||
payment_method: 'pm_card_visa', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"name": "mjs", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"dependencies": { | ||
"stripe": "file:../../" | ||
}, | ||
"scripts": { | ||
"clean": "rm -rf node_modules && rm -rf dist", | ||
"build": "esbuild index.js --bundle --platform=node --minify --target=es2020 --outdir=dist", | ||
"start": "node dist/index.js" | ||
}, | ||
"devDependencies": { | ||
"esbuild": "^0.20.2" | ||
} | ||
} |