Skip to content

🎥 Make videos programmatically with React

json backwards compatibility for new lambda payload

Jonny Burger20ae40c45b15
diff --git a/packages/lambda/src/shared/call-lambda.ts b/packages/lambda/src/shared/call-lambda.ts
index 72726f3f2c..ed62c36dc1 100644
--- a/packages/lambda/src/shared/call-lambda.ts
+++ b/packages/lambda/src/shared/call-lambda.ts
@@ -64,15 +64,34 @@ export const callLambda = async <T extends LambdaRoutines>({
}
const string = Buffer.from(responsePayload).toString();
+ const json = parseJson<T>(string);
- const json = JSON.parse(string) as
+ return json;
+};
+
+const parseJson = <T extends LambdaRoutines>(input: string) => {
+ let json = JSON.parse(input) as
| OrError<Awaited<LambdaReturnValues[T]>>
| {
errorType: string;
errorMessage: string;
trace: string[];
+ }
+ | {
+ statusCode: string;
+ body: string;
};
+ if ('statusCode' in json) {
+ json = JSON.parse(json.body) as
+ | OrError<Awaited<LambdaReturnValues[T]>>
+ | {
+ errorType: string;
+ errorMessage: string;
+ trace: string[];
+ };
+ }
+
if ('errorMessage' in json) {
const err = new Error(json.errorMessage);
err.name = json.errorType;
@@ -80,6 +99,13 @@ export const callLambda = async <T extends LambdaRoutines>({
throw err;
}
+ // This will not happen, it is for narrowing purposes
+ if ('statusCode' in json) {
+ throw new Error(
+ `Lambda function failed with status code ${json.statusCode}`
+ );
+ }
+
if (json.type === 'error') {
const err = new Error(json.message);
err.stack = json.stack;