Skip to content
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

build: update gaxios & gcp-metadata to 6.0.0, update @types/node to 20.4.2, decrease puppeteer to ^19.0.0, distinguish status and code in error handling. #1592

Merged
merged 5 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"dependencies": {
"base64-js": "^1.3.0",
"ecdsa-sig-formatter": "^1.0.11",
"gaxios": "^5.0.0",
"gcp-metadata": "^5.3.0",
"gaxios": "^6.0.0",
"gcp-metadata": "^6.0.0",
"gtoken": "^7.0.0",
"jws": "^4.0.0",
"lru-cache": "^6.0.0"
Expand All @@ -34,7 +34,7 @@
"@types/mocha": "^9.0.0",
"@types/mv": "^2.1.0",
"@types/ncp": "^2.0.1",
"@types/node": "^16.0.0",
"@types/node": "^20.4.2",
"@types/sinon": "^10.0.0",
"assert-rejects": "^1.0.0",
"c8": "^8.0.0",
Expand All @@ -57,7 +57,7 @@
"ncp": "^2.0.0",
"nock": "^13.0.0",
"null-loader": "^4.0.0",
"puppeteer": "^20.0.0",
"puppeteer": "^19.0.0",
"sinon": "^15.0.0",
"ts-loader": "^8.0.0",
"typescript": "^5.1.6",
Expand Down
2 changes: 1 addition & 1 deletion src/auth/computeclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export class Compute extends OAuth2Client {
protected wrapError(e: GaxiosError) {
const res = e.response;
if (res && res.status) {
e.code = res.status.toString();
e.status = res.status;
if (res.status === 403) {
e.message =
'A Forbidden error was returned while attempting to retrieve an access ' +
Expand Down
7 changes: 3 additions & 4 deletions src/transporters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export class DefaultTransporter implements Transporter {
// ensure the user isn't passing in request-style options
opts = this.configure(opts);
validate(opts);

return request<T>(opts).catch(e => {
throw this.processError(e);
});
Expand All @@ -97,7 +96,7 @@ export class DefaultTransporter implements Transporter {
if (res && body && body.error && res.status !== 200) {
if (typeof body.error === 'string') {
err.message = body.error;
err.code = res.status.toString();
err.status = res.status;
} else if (Array.isArray(body.error.errors)) {
err.message = body.error.errors
.map((err2: Error) => err2.message)
Expand All @@ -106,12 +105,12 @@ export class DefaultTransporter implements Transporter {
err.errors = body.error.errors;
} else {
err.message = body.error.message;
err.code = body.error.code || res.status;
err.code = body.error.code;
}
} else if (res && res.status >= 400) {
// Consider all 4xx and 5xx responses errors.
err.message = body;
err.code = res.status.toString();
err.status = res.status;
}
return err;
}
Expand Down
12 changes: 6 additions & 6 deletions test/test.awsclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ describe('AwsClient', () => {
const client = new AwsClient(awsOptions);

await assert.rejects(client.retrieveSubjectToken(), {
code: '500',
status: 500,
});
scope.done();
});
Expand All @@ -420,7 +420,7 @@ describe('AwsClient', () => {
const client = new AwsClient(awsOptions);

await assert.rejects(client.retrieveSubjectToken(), {
code: '403',
status: 403,
});
scope.done();
});
Expand All @@ -438,7 +438,7 @@ describe('AwsClient', () => {
const client = new AwsClient(awsOptions);

await assert.rejects(client.retrieveSubjectToken(), {
code: '408',
status: 408,
});
scope.done();
});
Expand Down Expand Up @@ -605,7 +605,7 @@ describe('AwsClient', () => {
const client = new AwsClient(awsOptions);

await assert.rejects(client.getAccessToken(), {
code: '500',
status: 500,
});
scope.done();
});
Expand Down Expand Up @@ -707,7 +707,7 @@ describe('AwsClient', () => {
const client = new AwsClient(awsOptions);

await assert.rejects(client.retrieveSubjectToken(), {
code: '500',
status: 500,
});
scope.done();
});
Expand Down Expand Up @@ -985,7 +985,7 @@ describe('AwsClient', () => {
const client = new AwsClient(awsOptions);

await assert.rejects(client.getAccessToken(), {
code: '500',
status: 500,
});
scope.done();
});
Expand Down
4 changes: 2 additions & 2 deletions test/test.baseexternalclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2161,7 +2161,7 @@ describe('BaseExternalAccountClient', () => {
responseType: 'json',
}),
{
code: '401',
status: 401,
}
);

Expand Down Expand Up @@ -2238,7 +2238,7 @@ describe('BaseExternalAccountClient', () => {
responseType: 'json',
}),
{
code: '403',
status: 403,
}
);

Expand Down
4 changes: 2 additions & 2 deletions test/test.downscopedclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@
this.credentials.expiry_date = expirationTime;
}

async getRequestHeaders(url?: string): Promise<Headers> {

Check warning on line 57 in test/test.downscopedclient.ts

View workflow job for this annotation

GitHub Actions / lint

'url' is defined but never used
throw new Error('Not implemented.');
}

request<T>(opts: GaxiosOptions): GaxiosPromise<T> {

Check warning on line 61 in test/test.downscopedclient.ts

View workflow job for this annotation

GitHub Actions / lint

'opts' is defined but never used
throw new Error('Not implemented.');
}
}
Expand Down Expand Up @@ -1185,7 +1185,7 @@
responseType: 'json',
}),
{
code: '401',
status: 401,
}
);

Expand Down Expand Up @@ -1262,7 +1262,7 @@
responseType: 'json',
}),
{
code: '403',
status: 403,
}
);
scopes.forEach(scope => scope.done());
Expand Down
4 changes: 2 additions & 2 deletions test/test.externalaccountauthorizeduserclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,7 @@ describe('ExternalAccountAuthorizedUserClient', () => {
responseType: 'json',
}),
{
code: '401',
status: 401,
}
);

Expand Down Expand Up @@ -752,7 +752,7 @@ describe('ExternalAccountAuthorizedUserClient', () => {
responseType: 'json',
}),
{
code: '403',
status: 403,
}
);
scopes.forEach(scope => scope.done());
Expand Down
4 changes: 2 additions & 2 deletions test/test.identitypoolclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ describe('IdentityPoolClient', () => {
const client = new IdentityPoolClient(urlSourcedOptions);

await assert.rejects(client.retrieveSubjectToken(), {
code: '404',
status: 404,
});
scope.done();
});
Expand Down Expand Up @@ -1033,7 +1033,7 @@ describe('IdentityPoolClient', () => {
const client = new IdentityPoolClient(urlSourcedOptions);

await assert.rejects(client.getAccessToken(), {
code: '404',
status: 404,
});
scope.done();
});
Expand Down
6 changes: 2 additions & 4 deletions test/test.oauth2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -819,9 +819,8 @@ describe('oauth2', () => {
.replyWithFile(200, certsResPath);
client.getFederatedSignonCerts((err, certs) => {
assert.strictEqual(err, null);
assert.strictEqual(Object.keys(certs!).length, 2);
assert.notStrictEqual(
certs!.a15eea964ab9cce480e5ef4f47cb17b9fa7d0b21,
certs!['a15eea964ab9cce480e5ef4f47cb17b9fa7d0b21'],
null
);
assert.notStrictEqual(
Expand Down Expand Up @@ -861,8 +860,7 @@ describe('oauth2', () => {
.replyWithFile(200, pubkeysResPath);
client.getIapPublicKeys((err, pubkeys) => {
assert.strictEqual(err, null);
assert.strictEqual(Object.keys(pubkeys!).length, 2);
assert.notStrictEqual(pubkeys!.f9R3yg, null);
assert.notStrictEqual(pubkeys!['f9R3yg'], null);
assert.notStrictEqual(pubkeys!['2nMJtw'], null);
scope.done();
done();
Expand Down
2 changes: 1 addition & 1 deletion test/test.transporters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
error => {
scope.done();
assert.strictEqual(error!.message, 'Not found');
assert.strictEqual((error as RequestError).code, '404');
assert.strictEqual((error as RequestError).status, 404);
done();
}
);
Expand Down Expand Up @@ -155,7 +155,7 @@
assert.strictEqual(res!.status, 200);
done();
},
_error => {

Check warning on line 158 in test/test.transporters.ts

View workflow job for this annotation

GitHub Actions / lint

'_error' is defined but never used
scope.done();
done('Unexpected promise failure');
}
Expand Down
Loading