Skip to content

Commit

Permalink
fix(AWS DynamoDB Node): Improve error message parsing (#7793)
Browse files Browse the repository at this point in the history
Github issue / Community forum post (link here to close automatically):
  • Loading branch information
maspio authored and netroy committed Nov 29, 2023
1 parent 0c881f1 commit df06163
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions packages/nodes-base/nodes/Aws/DynamoDB/GenericFunctions.ts
Expand Up @@ -37,9 +37,11 @@ export async function awsApiRequest(
(await this.helpers.requestWithAuthentication.call(this, 'aws', requestOptions)) as string,
);
} catch (error) {
const errorMessage =
const statusCode = (error.statusCode || error.cause?.statusCode) as number;
let errorMessage =
error.response?.body?.message || error.response?.body?.Message || error.message;
if (error.statusCode === 403) {

if (statusCode === 403) {
if (errorMessage === 'The security token included in the request is invalid.') {
throw new Error('The AWS credentials are not valid!');
} else if (
Expand All @@ -51,7 +53,13 @@ export async function awsApiRequest(
}
}

throw new Error(`AWS error response [${error.statusCode}]: ${errorMessage}`);
if (error.cause?.error) {
try {
errorMessage = JSON.parse(error.cause?.error).message;
} catch (ex) {}
}

throw new Error(`AWS error response [${statusCode}]: ${errorMessage}`);
}
}

Expand Down

0 comments on commit df06163

Please sign in to comment.