Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kjin committed Mar 23, 2018
1 parent c5681b2 commit 2a51cab
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 53 deletions.
84 changes: 37 additions & 47 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/trace-writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import * as common from '@google-cloud/common';
import {AxiosError} from 'axios';
import * as gcpMetadata from 'gcp-metadata';
import {OutgoingHttpHeaders} from 'http';
import * as os from 'os';
Expand Down Expand Up @@ -178,7 +179,7 @@ export class TraceWriter extends common.Service {
.then((res) => {
cb(res.data); // hostname
})
.catch((err) => {
.catch((err: AxiosError) => {
if (err.code !== 'ENOTFOUND') {
// We are running on GCP.
this.logger.warn('Unable to retrieve GCE hostname.', err);
Expand All @@ -192,7 +193,7 @@ export class TraceWriter extends common.Service {
.then((res) => {
cb(res.data); // instance ID
})
.catch((err) => {
.catch((err: AxiosError) => {
if (err.code !== 'ENOTFOUND') {
// We are running on GCP.
this.logger.warn('Unable to retrieve GCE instance id.', err);
Expand All @@ -215,7 +216,11 @@ export class TraceWriter extends common.Service {
.then((res) => {
cb(null, res.data); // project ID
})
.catch((err) => {
.catch((err: AxiosError) => {
if (err.response && err.response.status === 503) {
err.message +=
' This may be due to a temporary server error; please try again later.';
}
cb(err);
});
}
Expand Down
6 changes: 3 additions & 3 deletions test/nocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function projectId(status: number|(() => string), reply?: () => string) {
return nock('http://metadata.google.internal')
.get('/computeMetadata/v1/project/project-id')
.once()
.reply(200, reply, {'Metadata-Flavor': 'Google'});
.reply(status, reply, {'Metadata-Flavor': 'Google'});
}

export function instanceId(
Expand All @@ -51,7 +51,7 @@ export function instanceId(
return nock('http://metadata.google.internal')
.get('/computeMetadata/v1/instance/id')
.once()
.reply(200, reply, {'Metadata-Flavor': 'Google'});
.reply(status, reply, {'Metadata-Flavor': 'Google'});
}

export function hostname(status: number|(() => string), reply?: () => string) {
Expand All @@ -62,7 +62,7 @@ export function hostname(status: number|(() => string), reply?: () => string) {
return nock('http://metadata.google.internal')
.get('/computeMetadata/v1/instance/hostname')
.once()
.reply(200, reply, {'Metadata-Flavor': 'Google'});
.reply(status, reply, {'Metadata-Flavor': 'Google'});
}

export function patchTraces<T extends {} = {}>(
Expand Down

0 comments on commit 2a51cab

Please sign in to comment.