Skip to content

Commit

Permalink
fix lambda error response payload for aws v3 (#566)
Browse files Browse the repository at this point in the history
  • Loading branch information
MCarlomagno authored May 17, 2024
1 parent a4f42cc commit 41c14ef
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/base/src/autotask/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import Lambda, { _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 41c14ef

Please sign in to comment.