Skip to content

Commit 0cc6c9e

Browse files
author
Nick Cook
committed
address feedback
1 parent 0ca1215 commit 0cc6c9e

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

aml-ai/listLocations.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
'use strict';
1717

18-
const main = (projectId = process.env.GOOGLE_CLOUD_PROJECT) => {
18+
const main = async () => {
1919
// [START antimoneylaunderingai_list_locations]
2020
// Import google-auth-library for authentication.
2121
const {GoogleAuth} = require('google-auth-library');
@@ -25,17 +25,26 @@ const main = (projectId = process.env.GOOGLE_CLOUD_PROJECT) => {
2525
scopes: 'https://www.googleapis.com/auth/cloud-platform',
2626
headers: {'Content-Type': 'application/json; charset=utf-8'},
2727
});
28-
// TODO(developer): uncomment these lines before running the sample
29-
// const projectId = 'my-project-id';
28+
// TODO(developer): update the project ID as needed
29+
const projectId = process.env.GOOGLE_CLOUD_PROJECT;
3030
const url = `https://financialservices.googleapis.com/v1/projects/${projectId}/locations`;
3131
const client = await auth.getClient();
32-
const response = await client.request({url, method: 'GET'});
32+
let response;
33+
try {
34+
response = await client.request({url, method: 'GET'});
35+
} catch (err) {
36+
throw new Error(`API request failed: ${err}`);
37+
}
38+
3339
console.log(JSON.stringify(response.data));
3440
};
3541

36-
listLocations();
42+
return await listLocations();
3743
// [END antimoneylaunderingai_list_locations]
3844
};
3945

40-
// node listLocations.js <projectId>
41-
main(...process.argv.slice(2));
46+
// node listLocations.js
47+
main().catch(err => {
48+
console.log(err);
49+
process.exitCode = 1;
50+
});

aml-ai/system-test/aml-ai.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ const cwd = path.join(__dirname, '..');
2121
const {execSync} = require('child_process');
2222
const {it} = require('mocha');
2323

24-
const projectId = process.env.GCLOUD_PROJECT;
2524
const cloudRegion = 'us-central1';
2625

2726
it('should get the AML AI API locations', () => {
28-
const output = execSync(`node listLocations.js ${projectId}`, {cwd});
27+
const output = execSync('node listLocations.js', {cwd});
2928
assert.ok(output.includes(cloudRegion));
3029
});

0 commit comments

Comments
 (0)