Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/__tests__/linkup-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
LinkupInvalidRequestError,
LinkupNoResultError,
LinkupPaymentRequiredError,
LinkupTaskNotFoundError,
LinkupTasksQueueLimitExceededError,
LinkupTooManyRequestsError,
LinkupUnknownError,
} from '../errors';
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
26 changes: 26 additions & 0 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions src/utils/refine-error.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
LinkupInvalidRequestError,
LinkupNoResultError,
LinkupPaymentRequiredError,
LinkupTaskNotFoundError,
LinkupTasksQueueLimitExceededError,
LinkupTooManyRequestsError,
LinkupUnknownError,
} from '../errors';
Expand Down Expand Up @@ -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:
Expand Down