Skip to content

Commit

Permalink
fix lambda error response payload for aws v3
Browse files Browse the repository at this point in the history
  • Loading branch information
MCarlomagno committed May 17, 2024
1 parent a4f42cc commit 478c4a2
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/base/src/autotask/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import Lambda, { _Blob } from 'aws-sdk/clients/lambda';
import { _Blob } from 'aws-sdk/clients/lambda';
import { rateLimitModule, RateLimitModule } from '../utils/rate-limit';
import { getTimestampInSeconds } from '../utils/time';
import { getLambdaFromCredentials, isLambdaV3, LambdaLike, PayloadResponseV2, PayloadResponseV3 } from '../utils/lambda';
import { getLambdaFromCredentials, isLambdaV3, isV3ResponsePayload, LambdaLike, PayloadResponseV2, PayloadResponseV3 } from '../utils/lambda';

// do our best to get .errorMessage, but return object by default
function cleanError(payload?: PayloadResponseV2 | PayloadResponseV3): PayloadResponseV2 | PayloadResponseV3 {
if (!payload) {
return 'Error occurred, but error payload was not defined';
}
const error = isV3ResponsePayload(payload) ? payload.transformToString() : payload;
try {
const errMsg = JSON.parse(payload.toString()).errorMessage;
const errMsg = JSON.parse(error.toString()).errorMessage;
if (errMsg) {
return errMsg;
}
} catch (e) {}
return payload;

return error;
}

export abstract class BaseAutotaskClient {
Expand Down

0 comments on commit 478c4a2

Please sign in to comment.