Skip to content

🎥 Make videos programmatically with React

handle 303 status code

Jonny Burgerd5d697d1280d
diff --git a/packages/renderer/src/assets/read-file.ts b/packages/renderer/src/assets/read-file.ts
index a3782a2551..8bebe511be 100644
--- a/packages/renderer/src/assets/read-file.ts
+++ b/packages/renderer/src/assets/read-file.ts
@@ -1,5 +1,6 @@
import http from 'http';
import https from 'https';
+import {redirectStatusCodes} from '../redirect-status-codes';
const getClient = (url: string) => {
if (url.startsWith('https://')) {
@@ -34,12 +35,7 @@ export const readFile = async (
}
const file = await readFileWithoutRedirect(url);
- if (
- file.statusCode === 302 ||
- file.statusCode === 301 ||
- file.statusCode === 307 ||
- file.statusCode === 308
- ) {
+ if (redirectStatusCodes.includes(file.statusCode as number)) {
if (!file.headers.location) {
throw new Error(
`Received a status code ${file.statusCode} but no "Location" header while calling ${file.headers.location}`
diff --git a/packages/renderer/src/redirect-status-codes.ts b/packages/renderer/src/redirect-status-codes.ts
new file mode 100644
index 0000000000..6b698f10de
--- /dev/null
+++ b/packages/renderer/src/redirect-status-codes.ts
@@ -0,0 +1 @@
+export const redirectStatusCodes = [301, 302, 303, 304, 307, 308];
diff --git a/packages/renderer/src/set-props-and-env.ts b/packages/renderer/src/set-props-and-env.ts
index ec2edd2ac7..b090be2126 100644
--- a/packages/renderer/src/set-props-and-env.ts
+++ b/packages/renderer/src/set-props-and-env.ts
@@ -3,6 +3,7 @@ import type {Page} from './browser/BrowserPage';
import {DEFAULT_TIMEOUT} from './browser/TimeoutSettings';
import {normalizeServeUrl} from './normalize-serve-url';
import {puppeteerEvaluateWithCatch} from './puppeteer-evaluate';
+import {redirectStatusCodes} from './redirect-status-codes';
import {validatePuppeteerTimeout} from './validate-puppeteer-timeout';
export const setPropsAndEnv = async ({
@@ -98,15 +99,7 @@ export const setPropsAndEnv = async ({
});
}
- if (
- status !== 200 &&
- status !== 301 &&
- status !== 302 &&
- status !== 303 &&
- status !== 304 &&
- status !== 307 &&
- status !== 308
- ) {
+ if (!redirectStatusCodes.every((code) => code !== status)) {
throw new Error(
`Error while getting compositions: Tried to go to ${urlToVisit} but the status code was ${status} instead of 200. Does the site you specified exist?`
);