-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!: Use Error#cause
in GaxiosError
#661
Changes from all commits
f9a2d69
59a4655
d5bda53
0190a1d
9b76bba
85a81c6
86c29db
a45d9e1
99ba060
8cd6e2a
f5a4cae
ad63f64
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,10 +144,15 @@ export class Gaxios { | |
} | ||
return translatedResponse; | ||
} catch (e) { | ||
const err = | ||
e instanceof GaxiosError | ||
? e | ||
: new GaxiosError((e as Error).message, opts, undefined, e as Error); | ||
let err: GaxiosError; | ||
|
||
if (e instanceof GaxiosError) { | ||
err = e; | ||
} else if (e instanceof Error) { | ||
err = new GaxiosError(e.message, opts, undefined, e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (just for my curiosity) - why wouldn't we contstruct the error with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It allows |
||
} else { | ||
err = new GaxiosError(new Error(e as '').message, opts, undefined, e); | ||
} | ||
|
||
const {shouldRetry, config} = await getRetryConfig(err); | ||
if (shouldRetry && config) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,9 +103,8 @@ function shouldRetryRequest(err: GaxiosError) { | |
const config = getConfig(err); | ||
|
||
if ( | ||
(err.config.signal?.aborted && err.error?.name !== 'TimeoutError') || | ||
err.name === 'AbortError' || | ||
err.error?.name === 'AbortError' | ||
(err.config.signal?.aborted && err.code !== 'TimeoutError') || | ||
err.code === 'AbortError' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are we getting rid of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That line could never be true as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, this doesn't seem entirely relevant to this PR, I'm concerned it could have unintended consequences (even if it is a no-op). Would it be alright to leave it as a follow up? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It’s not relevant, but is a one-line change. Not at all a big deal. Not worthy of a separate PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, those are often the most tricky! We've had this situation occur before. Until we have very robust integration testing, I think it would be wise to make small incremental changes. If we had good integration tests I'd feel better about it! |
||
) { | ||
return false; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the documentation, it seems like cause is in addition to, not instead of the error. Is it possible to set both in GaxiosError for it to not be a breaking change?
Also, seems like
any
is better thanunknown
here, WDYT?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As
GaxiosError
is an error itself (with a few additional custom params) it would enable a chain ofError
s to be appropriately logged along with each individual call stacks - providing a complete context for customers. Theerror
param was a stop-gap, but often it would not be used properly. I think cleanly migrating would be a more optimal UX instead of both.unknown
is the appropriate type - cause could be anything, but should be verified through type checks.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps a less destructive way then would be to add a deprecated tag to error, and simply continue to have it there? I'm concerned that it's a needlessly breaking change, especially since we're bundling a few other breaking changes in this release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A quick code search in
googleapis
will show virtually none of our libraries are using this property and it will be far more intuitive in the future to simply clean it up now.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right but perhaps it's being used by external users?