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+ } ) ;
0 commit comments