diff --git a/packages/http-client/src/index.d.ts b/packages/http-client/src/index.d.ts index 35bdc41498..e490f98882 100644 --- a/packages/http-client/src/index.d.ts +++ b/packages/http-client/src/index.d.ts @@ -8,14 +8,16 @@ export type Page = { id: string; root: [string, string]; }; -export type Project = { - [string]: - | { - page: Page; - tree: BaseInstance; - props: Array | []; - breakpoints: Array | null; - css: string; - } - | string; -}; +export type Project = + | { + pages: { + [string]: { + page: Page; + tree: BaseInstance; + props: Array | []; + breakpoints: Array | null; + css: string; + }; + }; + } + | Error; diff --git a/packages/http-client/src/index.test.ts b/packages/http-client/src/index.test.ts index cb372d45fa..bdf0120436 100644 --- a/packages/http-client/src/index.test.ts +++ b/packages/http-client/src/index.test.ts @@ -13,6 +13,9 @@ describe("getProjectDetails", () => { apiUrl, projectId: morePagesProjectId, }); + if (response instanceof Error) { + throw response; + } expect(Object.keys(response.pages).length > 1).toBeTruthy(); }); test("does not include pages", async () => { @@ -20,6 +23,9 @@ describe("getProjectDetails", () => { apiUrl, projectId: onlyHomeProjectId, }); + if (response instanceof Error) { + throw response; + } expect(Object.keys(response.pages).length === 1).toBeTruthy(); }); test("loads existing project", async () => { diff --git a/packages/http-client/src/index.ts b/packages/http-client/src/index.ts index 21ae3a2fa2..2c497122f3 100644 --- a/packages/http-client/src/index.ts +++ b/packages/http-client/src/index.ts @@ -7,7 +7,7 @@ export const loadProject = async ({ }: { apiUrl: string; projectId: string; -}): Promise => { +}): Promise => { try { if (apiUrl === undefined) { throw new Error("Webstudio API URL is required."); @@ -24,6 +24,6 @@ export const loadProject = async ({ if (error instanceof Error) { return error; } - return "Unknown error"; + return new Error("Unknown error"); } };