Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
r? @richardm-stripe
cc @ob-stripe (especially on
doc_url
which I am adding here – should we add that to all libs?)cc @stripe/api-libraries
cc @cah-dunn
This addresses #809 and a few related issues I noticed with our handling of errors and their types.
StripeError.generate()
static method, which returns the appropriate subclass based on atype
string (and is appropriately typed as such).StripeError
constructor.generate
available at the top-level, so you can doStripe.errors.generate({})
which I think is much prettier thanStripe.errors.StripeError.generate({})
. Feedback welcome on whether this is a good idea or not.StripeInvalidGrantError
, which I think we had forgotten to add types for before.authentication_error
andrate_limit_error
in.generate()
.One tradeoff I made which I don't feel great about is that the constructor/generate is now typed more loosely than the object itself, so for example if you
new StripeError()
it will haveundefined
values forrawType
,requestId
, andheaders
, even though all of those are typed as being required fields onStripeError
instances.We could either:
'unknown'
,''
,{}
.I'm leaning towards (2) or (3+4) and would value input from the community and from fellow Stripes.