Closed sdsanders closed 8 months ago
Hi there @sdsanders ! Thanks for the bug report and for the minimal repro. This is happening because in the error object constructor, type
is set to the constructor name: https://github.com/stripe/stripe-node/blob/master/src/Error.ts#L54
A fix on our side would be to explicitly specify the type as a string in the StripeError
constructor. I'll have a PR up for this soon, as it seems like it would be relatively non-intrusive.
The fix has been merged! The changes will be included in today's release.
Update: Included in v14.22.0
The fix has been merged! The changes will be included in today's release.
Update: Included in v14.22.0
Thanks so much! Can confirm that this fixes the issue in our setup.
Describe the bug
When bundling and minifying using a tool like esbuild, the
type
included in errors thrown by Stripe is also minified into a shorter string. Strings are usually safe from minification so this behavior is unexpected.To Reproduce
Minimal reproduction: https://github.com/sdsanders/stripe-minify-error Run
npm run build && npm start
- incorrecterror.type
will be logged Runnpm run build:unminified && npm start
- correcterror.type
will be loggedExpected behavior
Error type string should remain intact after minification.
Code snippets
No response
OS
macOs
Node version
Node v18.19.0
Library version
stripe-node
API version
2023-10-16
Additional context
Minifying might not be a super common practice server-side but it can have some advantages. We run on AWS Lambda which is usually resource constrained and minification can improve cold start times.