@@ -146,7 +146,10 @@ export class DatabaseConnector {
146146 } ) ;
147147
148148 if ( ! response . Reservations || response . Reservations . length === 0 ) {
149- throw new Error ( `No bastion host found for environment: ${ environment } ` ) ;
149+ throw new Error (
150+ `No bastion host found for environment: ${ environment } \n` +
151+ ` Expected EC2 instance tag: indicator-bastion-${ environment } -host`
152+ ) ;
150153 }
151154
152155 const instance = response . Reservations [ 0 ] . Instances ?. [ 0 ] ;
@@ -182,18 +185,25 @@ export class DatabaseConnector {
182185 ? `/indicator/indicator-api/${ environment } /database-environment-variables`
183186 : `/indicator/${ database } -api/${ environment } /database-environment-variables` ;
184187
185- const response = await this . callWithMfaRetry ( async ( ) => {
186- const command = new GetParameterCommand ( {
187- Name : parameterName
188+ try {
189+ const response = await this . callWithMfaRetry ( async ( ) => {
190+ const command = new GetParameterCommand ( {
191+ Name : parameterName
192+ } ) ;
193+ return await this . ssmClient . send ( command ) ;
188194 } ) ;
189- return await this . ssmClient . send ( command ) ;
190- } ) ;
191195
192- if ( ! response . Parameter || ! response . Parameter . Value ) {
193- throw new Error ( `Database info not found for ${ database } in environment: ${ environment } ` ) ;
194- }
196+ if ( ! response . Parameter || ! response . Parameter . Value ) {
197+ throw new Error ( `Database info not found for ${ database } in environment: ${ environment } ` ) ;
198+ }
195199
196- return JSON . parse ( response . Parameter . Value ) ;
200+ return JSON . parse ( response . Parameter . Value ) ;
201+ } catch ( error : any ) {
202+ // Re-throw with AWS SDK error details
203+ const errorName = error . name || 'UnknownError' ;
204+ const errorMessage = error . message || String ( error ) ;
205+ throw new Error ( `${ errorName } : ${ errorMessage } \n Parameter: ${ parameterName } ` ) ;
206+ }
197207 }
198208
199209 /**
@@ -202,20 +212,27 @@ export class DatabaseConnector {
202212 async getDatabasePassword ( environment : string , database : string = 'indicator' ) : Promise < string > {
203213 const dbInfo = await this . getDatabaseInfo ( environment , database ) ;
204214
205- const command = new GetSecretValueCommand ( {
206- SecretId : dbInfo . DATABASE_SECRET_ARN
207- } ) ;
215+ try {
216+ const command = new GetSecretValueCommand ( {
217+ SecretId : dbInfo . DATABASE_SECRET_ARN
218+ } ) ;
208219
209- const response = await this . callWithMfaRetry ( async ( ) => {
210- return await this . secretsClient . send ( command ) ;
211- } ) ;
220+ const response = await this . callWithMfaRetry ( async ( ) => {
221+ return await this . secretsClient . send ( command ) ;
222+ } ) ;
212223
213- if ( ! response . SecretString ) {
214- throw new Error ( `Database password not found in secret: ${ dbInfo . DATABASE_SECRET_ARN } ` ) ;
215- }
224+ if ( ! response . SecretString ) {
225+ throw new Error ( `Database password not found in secret: ${ dbInfo . DATABASE_SECRET_ARN } ` ) ;
226+ }
216227
217- const secretValue = JSON . parse ( response . SecretString ) ;
218- return secretValue . password || secretValue . PASSWORD ;
228+ const secretValue = JSON . parse ( response . SecretString ) ;
229+ return secretValue . password || secretValue . PASSWORD ;
230+ } catch ( error : any ) {
231+ // Re-throw with AWS SDK error details
232+ const errorName = error . name || 'UnknownError' ;
233+ const errorMessage = error . message || String ( error ) ;
234+ throw new Error ( `${ errorName } : ${ errorMessage } \n Secret ARN: ${ dbInfo . DATABASE_SECRET_ARN } ` ) ;
235+ }
219236 }
220237
221238 /**
@@ -649,7 +666,13 @@ export class DatabaseConnector {
649666 } ) ;
650667
651668 } catch ( error ) {
652- console . error ( chalk . red ( 'Error setting up database connection:' ) , error instanceof Error ? error . message : String ( error ) ) ;
669+ console . error ( chalk . red ( 'Error setting up database connection:' ) ) ;
670+ if ( error instanceof Error ) {
671+ console . error ( chalk . red ( 'Message:' ) , error . message ) ;
672+ console . error ( chalk . red ( 'Stack:' ) , error . stack ) ;
673+ } else {
674+ console . error ( chalk . red ( 'Error:' ) , error ) ;
675+ }
653676 throw error ;
654677 }
655678 }
0 commit comments