diff --git a/src/__tests__/linkup-client.test.ts b/src/__tests__/linkup-client.test.ts index cadbc56..81a6789 100644 --- a/src/__tests__/linkup-client.test.ts +++ b/src/__tests__/linkup-client.test.ts @@ -9,6 +9,8 @@ import { LinkupInvalidRequestError, LinkupNoResultError, LinkupPaymentRequiredError, + LinkupTaskNotFoundError, + LinkupTasksQueueLimitExceededError, LinkupTooManyRequestsError, LinkupUnknownError, } from '../errors'; @@ -732,6 +734,15 @@ describe('LinkupClient', () => { statusCode: 403, }, }, + { + description: '404 TASK_NOT_FOUND', + ErrorClass: LinkupTaskNotFoundError, + expectedMessage: 'Task task-123 not found.', + input: { + error: { code: 'TASK_NOT_FOUND', details: [], message: 'Task task-123 not found.' }, + statusCode: 404, + }, + }, { description: '429 INSUFFICIENT_FUNDS_CREDITS', ErrorClass: LinkupInsufficientCreditError, @@ -758,6 +769,21 @@ describe('LinkupClient', () => { statusCode: 429, }, }, + { + description: '429 TASKS_QUEUE_LIMIT_EXCEEDED', + ErrorClass: LinkupTasksQueueLimitExceededError, + expectedMessage: + 'Too many pending tasks. You have 0 slots available (max 100). Please wait for some tasks to complete before submitting new ones.', + input: { + error: { + code: 'TASKS_QUEUE_LIMIT_EXCEEDED', + details: [], + message: + 'Too many pending tasks. You have 0 slots available (max 100). Please wait for some tasks to complete before submitting new ones.', + }, + statusCode: 429, + }, + }, { description: '429 TOO_MANY_REQUESTS', ErrorClass: LinkupTooManyRequestsError, diff --git a/src/errors.ts b/src/errors.ts index b525f96..c2f3be7 100644 --- a/src/errors.ts +++ b/src/errors.ts @@ -46,6 +46,19 @@ export class LinkupAuthenticationError extends Error { } } +// Task not found error, raised when the Linkup API returns a 404 status code. +// It is returned when a task or research task does not exist. +export class LinkupTaskNotFoundError extends LinkupError { + constructor(message?: string) { + super(message); + this.name = LinkupTaskNotFoundError.name; + + if ('captureStackTrace' in Error) { + Error.captureStackTrace(this, LinkupTaskNotFoundError); + } + } +} + // Insufficient credit error, raised when the Linkup API returns a 429 status code. // It is returned when you have run out of credits. export class LinkupInsufficientCreditError extends LinkupError { @@ -59,6 +72,19 @@ export class LinkupInsufficientCreditError extends LinkupError { } } +// Tasks queue limit exceeded error, raised when the Linkup API returns a 429 status code. +// It is returned when you submit more pending tasks than your organization queue allows. +export class LinkupTasksQueueLimitExceededError extends LinkupError { + constructor(message?: string) { + super(message); + this.name = LinkupTasksQueueLimitExceededError.name; + + if ('captureStackTrace' in Error) { + Error.captureStackTrace(this, LinkupTasksQueueLimitExceededError); + } + } +} + // Too many requests error, raised when the Linkup API returns a 429 status code. // It is returned when you are sending too many requests at a time. export class LinkupTooManyRequestsError extends LinkupError { diff --git a/src/utils/refine-error.utils.ts b/src/utils/refine-error.utils.ts index e0d15fa..433604c 100644 --- a/src/utils/refine-error.utils.ts +++ b/src/utils/refine-error.utils.ts @@ -9,6 +9,8 @@ import { LinkupInvalidRequestError, LinkupNoResultError, LinkupPaymentRequiredError, + LinkupTaskNotFoundError, + LinkupTasksQueueLimitExceededError, LinkupTooManyRequestsError, LinkupUnknownError, } from '../errors'; @@ -54,11 +56,20 @@ export const refineError = (e: LinkupApiError): LinkupError => { case 401: case 403: return new LinkupAuthenticationError(message); + case 404: + switch (code) { + case 'TASK_NOT_FOUND': + return new LinkupTaskNotFoundError(message); + default: + return new LinkupUnknownError(`An unknown error occurred: ${error.message}`); + } case 429: switch (code) { case 'INSUFFICIENT_FUNDS_CREDITS': case 'EXCEED_BUDGET_LIMIT': return new LinkupInsufficientCreditError(message); + case 'TASKS_QUEUE_LIMIT_EXCEEDED': + return new LinkupTasksQueueLimitExceededError(message); case 'TOO_MANY_REQUESTS': return new LinkupTooManyRequestsError(message); default: