diff --git a/packages/rest-client/src/index.ts b/packages/rest-client/src/index.ts index 3c5f765f..17978547 100644 --- a/packages/rest-client/src/index.ts +++ b/packages/rest-client/src/index.ts @@ -33,7 +33,7 @@ export { Problems } from './types/Problems' export { ServerErrorResponse } from './types/ServerErrorResponse' export { Webhook } from './types/Webhook' export { WebhookEvent } from './types/WebhookEvent' -export { StoreValue } from '@uploadcare/api-client-utils' +export { StoreValue, CancelError } from '@uploadcare/api-client-utils' export { Paginatable } from './types/Paginatable' export { Md5Function } from './lib/md5/Md5Function' export { diff --git a/packages/rest-client/src/tools/conversionJobPoller.test.ts b/packages/rest-client/src/tools/conversionJobPoller.test.ts index d264297a..aa7be7e7 100644 --- a/packages/rest-client/src/tools/conversionJobPoller.test.ts +++ b/packages/rest-client/src/tools/conversionJobPoller.test.ts @@ -4,6 +4,7 @@ import { testSettings } from '../../test/helpers' import { ConversionStatus } from '../types/ConversionStatus' import { ConversionType } from '../types/ConversionType' import { conversionJobPoller } from './conversionJobPoller' +import { delay } from '@uploadcare/api-client-utils' jest.setTimeout(60 * 1000) @@ -125,4 +126,31 @@ describe('conversionJobPoller', () => { }) ]) }) + + it('should be able to catch CancelError', async () => { + const path = `${DOCUMENT_UUID}/document/-/format/pdf/` + + const abortController = new AbortController() + + const promises = await conversionJobPoller( + { + type: ConversionType.DOCUMENT, + paths: [path], + store: false, + pollOptions: { + signal: abortController.signal + } + }, + testSettings + ) + await delay(0) + abortController.abort() + + expect.assertions(3) + expect(promises.length).toBe(1) + await promises[0].catch((err) => { + expect(err.name).toBe('CancelError') + expect(err.isCancel).toBeTrue() + }) + }) })