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
3 changes: 2 additions & 1 deletion src/__tests__/linkup-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import axios, { type AxiosResponse } from 'axios';
import { z } from 'zod';
import {
LinkupAuthenticationError,
LinkupBudgetLimitExceededError,
LinkupFetchError,
LinkupFetchResponseTooLargeError,
LinkupFetchUnsupportedContentTypeError,
Expand Down Expand Up @@ -786,7 +787,7 @@ describe('LinkupClient', () => {
},
{
description: '429 EXCEED_BUDGET_LIMIT',
ErrorClass: LinkupInsufficientCreditError,
ErrorClass: LinkupBudgetLimitExceededError,
expectedMessage: 'The API key has reached its budget limit.',
input: {
error: {
Expand Down
13 changes: 13 additions & 0 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ export class LinkupInsufficientCreditError extends LinkupError {
}
}

// Budget limit exceeded error, raised when the Linkup API returns a 429 status code.
// It is returned when the API key has reached its configured budget limit.
export class LinkupBudgetLimitExceededError extends LinkupError {
constructor(message?: string) {
super(message);
this.name = LinkupBudgetLimitExceededError.name;

if ('captureStackTrace' in Error) {
Error.captureStackTrace(this, LinkupBudgetLimitExceededError);
}
}
}

// 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 {
Expand Down
4 changes: 3 additions & 1 deletion src/utils/refine-error.utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
FetchUrlIsFileError,
LinkupAuthenticationError,
LinkupBudgetLimitExceededError,
LinkupError,
LinkupFetchError,
LinkupFetchResponseTooLargeError,
Expand Down Expand Up @@ -66,8 +67,9 @@ export const refineError = (e: LinkupApiError): LinkupError => {
case 429:
switch (code) {
case 'INSUFFICIENT_FUNDS_CREDITS':
case 'EXCEED_BUDGET_LIMIT':
return new LinkupInsufficientCreditError(message);
case 'EXCEED_BUDGET_LIMIT':
return new LinkupBudgetLimitExceededError(message);
case 'TASKS_QUEUE_LIMIT_EXCEEDED':
return new LinkupTasksQueueLimitExceededError(message);
case 'TOO_MANY_REQUESTS':
Expand Down