Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

js-sdk: normalize developer search transport errors

Karan Lokchandani3d7f89c82754
diff --git a/apps/js-sdk/firecrawl/src/__tests__/unit/v2/developer.test.ts b/apps/js-sdk/firecrawl/src/__tests__/unit/v2/developer.test.ts
index 98c6bef0d..5025e0fcb 100644
--- a/apps/js-sdk/firecrawl/src/__tests__/unit/v2/developer.test.ts
+++ b/apps/js-sdk/firecrawl/src/__tests__/unit/v2/developer.test.ts
@@ -1,5 +1,6 @@
import { describe, expect, jest, test } from "@jest/globals";
import { FirecrawlClient } from "../../../v2/client";
+import { SdkError } from "../../../v2/types";
const response = {
success: true,
@@ -74,6 +75,27 @@ describe("developerSearch", () => {
expect(result).toEqual(response);
});
+ test("normalizes transport errors to SdkError", async () => {
+ const http = {
+ post: jest.fn(async () => {
+ throw {
+ isAxiosError: true,
+ code: "ECONNABORTED",
+ message: "request timed out",
+ };
+ }),
+ } as any;
+ const client = new FirecrawlClient({
+ apiKey: "test",
+ apiUrl: "http://localhost",
+ });
+ (client as any).http = http;
+
+ await expect(
+ client.developerSearch("network failure"),
+ ).rejects.toBeInstanceOf(SdkError);
+ });
+
test("accepts the flattened SPDX license response shape", async () => {
const flattened = {
...response,
diff --git a/apps/js-sdk/firecrawl/src/v2/methods/developer.ts b/apps/js-sdk/firecrawl/src/v2/methods/developer.ts
index d501c8573..c7954cccd 100644
--- a/apps/js-sdk/firecrawl/src/v2/methods/developer.ts
+++ b/apps/js-sdk/firecrawl/src/v2/methods/developer.ts
@@ -1,6 +1,9 @@
import type { DeveloperSearchOptions, DeveloperSearchResponse } from "../types";
import { HttpClient } from "../utils/httpClient";
-import { throwForBadResponse } from "../utils/errorHandler";
+import {
+ normalizeAxiosError,
+ throwForBadResponse,
+} from "../utils/errorHandler";
const ENDPOINT = "/v2/search/developer";
@@ -12,25 +15,36 @@ export async function developerSearch(
): Promise<DeveloperSearchResponse> {
if (!query || !query.trim()) throw new Error("query cannot be empty");
- const response = await http.post<DeveloperSearchResponse>(ENDPOINT, {
- query,
- ...(options.k !== undefined ? { k: options.k } : {}),
- ...(options.passages !== undefined ? { passages: options.passages } : {}),
- ...(options.types !== undefined ? { types: options.types } : {}),
- ...(options.repos !== undefined ? { repos: options.repos } : {}),
- ...(options.sources !== undefined ? { sources: options.sources } : {}),
- ...(options.language !== undefined ? { language: options.language } : {}),
- ...(options.topic !== undefined ? { topic: options.topic } : {}),
- ...(options.license !== undefined ? { license: options.license } : {}),
- ...(options.minStars !== undefined ? { min_stars: options.minStars } : {}),
- ...(options.maxStars !== undefined ? { max_stars: options.maxStars } : {}),
- ...(options.archived !== undefined ? { archived: options.archived } : {}),
- ...(options.fork !== undefined ? { fork: options.fork } : {}),
- ...(options.skills !== undefined ? { skills: options.skills } : {}),
- });
+ try {
+ const response = await http.post<DeveloperSearchResponse>(ENDPOINT, {
+ query,
+ ...(options.k !== undefined ? { k: options.k } : {}),
+ ...(options.passages !== undefined ? { passages: options.passages } : {}),
+ ...(options.types !== undefined ? { types: options.types } : {}),
+ ...(options.repos !== undefined ? { repos: options.repos } : {}),
+ ...(options.sources !== undefined ? { sources: options.sources } : {}),
+ ...(options.language !== undefined ? { language: options.language } : {}),
+ ...(options.topic !== undefined ? { topic: options.topic } : {}),
+ ...(options.license !== undefined ? { license: options.license } : {}),
+ ...(options.minStars !== undefined
+ ? { min_stars: options.minStars }
+ : {}),
+ ...(options.maxStars !== undefined
+ ? { max_stars: options.maxStars }
+ : {}),
+ ...(options.archived !== undefined ? { archived: options.archived } : {}),
+ ...(options.fork !== undefined ? { fork: options.fork } : {}),
+ ...(options.skills !== undefined ? { skills: options.skills } : {}),
+ });
- if (response.status !== 200) {
- throwForBadResponse(response, "search developer sources");
+ if (response.status !== 200 || !response.data?.success) {
+ throwForBadResponse(response, "search developer sources");
+ }
+ return response.data;
+ } catch (error: any) {
+ if (error?.isAxiosError) {
+ return normalizeAxiosError(error, "search developer sources");
+ }
+ throw error;
}
- return response.data;
}