Conversation
|
Warning: This pull request is touching the following templated files:
|
GaxiosError
| err.response?.data.error.message === 'File not found' | ||
| ); | ||
|
|
||
| assert.deepStrictEqual(err.cause, body.error); |
There was a problem hiding this comment.
Note: this assert works within the callback context as assert.rejects handles it properly.
| (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.
A few things here:
namecould never beAbortError(alwaysGaxiosError)- We can demonstrate best practices by not referencing the deprecated
GaxiosError#error - Notice the relevant retry tests did not need to change for this logic
| let err: GaxiosError; | ||
|
|
||
| if (e instanceof GaxiosError) { | ||
| err = e; | ||
| } else if (e instanceof Error) { | ||
| err = new GaxiosError(e.message, opts, undefined, e); | ||
| } else { | ||
| err = new GaxiosError('Unexpected Gaxios Error', opts, undefined, e); | ||
| } |
There was a problem hiding this comment.
Summary:
- in the first case we're using the existing GaxiosError
- in the second we're adopting an existing Error's message
- in the third some random, non-
Errormust've been thrown
Note:
- GaxiosError supports
easunknown
| * @internal | ||
| * @expiremental |
There was a problem hiding this comment.
We can open this up for external libraries later, if needed
| if (cause instanceof DOMException) { | ||
| // The DOMException's equivalent to code is its name | ||
| // E.g.: name = `TimeoutError`, code = number | ||
| // https://developer.mozilla.org/en-US/docs/Web/API/DOMException/name | ||
| this.code = cause.name; | ||
| } else if ( | ||
| cause && | ||
| typeof cause === 'object' && | ||
| 'code' in cause && | ||
| typeof cause.code === 'string' | ||
| ) { | ||
| this.code = cause.code; | ||
| } |
There was a problem hiding this comment.
Improved accuracy and type-checking as cause is unknown. DOMException is the only standard Error instance that has a numeric code rather than a string (and that property is deprecated).
| ## License | ||
|
|
||
| [Apache-2.0](https://github.com/googleapis/gaxios/blob/master/LICENSE) | ||
| [Apache-2.0](https://github.com/googleapis/gaxios/blob/main/LICENSE) |
There was a problem hiding this comment.
linkinator complaint
| }, | ||
| "devDependencies": { | ||
| "@octokit/rest": "^21.0.0", | ||
| "@octokit/rest": "^19.0.0", |
src/common.ts
Outdated
| cause && | ||
| typeof cause === 'object' && | ||
| 'code' in cause && | ||
| typeof cause.code === 'string' |
There was a problem hiding this comment.
| typeof cause.code === 'string' |
There was a problem hiding this comment.
Currently code comes as int32 so this would cause code to be undefined in a lot of places.
GaxiosErrorGaxiosError
sofisl
left a comment
There was a problem hiding this comment.
These changes mirror the previous processError function and pass current tests in google-api-nodejs-client.
GaxiosErrorGaxiosError
|
Commenting here so we can remember... It looks like the decision between returning error as code or string was already a discussion, Ben brought up the point that it could/should be either so let's just pass it through (without type-checking). |
…nto aip-193-gaxios-error
Co-authored-by: sofisl <55454395+sofisl@users.noreply.github.com>
Description
Adds AIP-193 recommendations to
GaxiosError, including:Error.message)Error.cause)History
Previously, some of this functionality was in
google-auth-librarywithin its now-removed transporter. It was within the transporter this logic predates this library itself (we were using request and axios at the time) and auth was the closest place to put such logic. This logic can now live where it belongs - gaxios.Some additional references for background:
Transportergoogle-auth-library-nodejs#1937src/transporters.tswrapCallback_pre-gaxiosImpact
This will improve the debugging experience for customers as the API-level error is easy to see while the GaxiosError context/details are preserved.
Testing
Updated tests to reflect. Note: many tests did not require changing as it is mostly backwards-compatible.
Additional Information
Fixes #572
Fixes #684
🦕