diff --git a/package.json b/package.json index 963f7af2..be07d116 100644 --- a/package.json +++ b/package.json @@ -72,8 +72,8 @@ "prepack": "tsc --build", "test-unit": "vitest run --coverage ./test/unit", "test-integration": "vitest run ./test/integration", - "test-all": "npm run tsd && vitest run --coverage", - "test": "npm run tsd && npm run test-unit", + "test-all": "vitest run --coverage", + "test": "yarn test-unit", "fix:formatting": "prettier --write .", "lint:formatting": "prettier --check ." }, diff --git a/src/Transloadit.ts b/src/Transloadit.ts index da314a28..ed14b1bc 100644 --- a/src/Transloadit.ts +++ b/src/Transloadit.ts @@ -746,18 +746,18 @@ export class Transloadit { // https://transloadit.com/blog/2012/04/introducing-rate-limiting/ if ( !( - statusCode === 413 && typeof body === 'object' && body != null && 'error' in body && - body.error === 'RATE_LIMIT_REACHED' && 'info' in body && typeof body.info === 'object' && body.info != null && 'retryIn' in body.info && typeof body.info.retryIn === 'number' && Boolean(body.info.retryIn) && - retryCount < this._maxRetries + retryCount < this._maxRetries && // 413 taken from https://transloadit.com/blog/2012/04/introducing-rate-limiting/ + // todo can it be removed? + ((statusCode === 413 && body.error === 'RATE_LIMIT_REACHED') || statusCode === 429) ) ) { throw new ApiError({ diff --git a/test/unit/mock-http.test.ts b/test/unit/mock-http.test.ts index be640cce..b59d6e65 100644 --- a/test/unit/mock-http.test.ts +++ b/test/unit/mock-http.test.ts @@ -178,7 +178,7 @@ describe('Mocked API tests', () => { const scope = nock('http://localhost') .post(createAssemblyRegex) - .reply(413, { error: 'RATE_LIMIT_REACHED', info: { retryIn: 0.01 } }) + .reply(429, { error: 'ASSEMBLY_STATUS_FETCHING_RATE_LIMIT_REACHED', info: { retryIn: 0.01 } }) .post(createAssemblyRegex) .reply(200, { ok: 'ASSEMBLY_EXECUTING' }) @@ -191,7 +191,7 @@ describe('Mocked API tests', () => { const scope = nock('http://localhost') .post(createAssemblyRegex) - .reply(413, { + .reply(429, { error: 'RATE_LIMIT_REACHED', message: 'Request limit reached', info: { retryIn: 0.01 }, @@ -199,7 +199,7 @@ describe('Mocked API tests', () => { await expect(client.createAssembly()).rejects.toThrow( expect.objectContaining({ - message: 'API error (HTTP 413) RATE_LIMIT_REACHED: Request limit reached', + message: 'API error (HTTP 429) RATE_LIMIT_REACHED: Request limit reached', code: 'RATE_LIMIT_REACHED', }) )