Skip to content

Commit b24f2a9

Browse files
committed
Fixed API calls to parse error messages as non-json
1 parent a76a640 commit b24f2a9

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/api/dashboard/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ export const DashboardApiClient = {
1515
);
1616

1717
if (!res.ok) {
18-
throw new Error(`Error fetching document: ${res.statusText}`);
18+
const message = await res.text();
19+
throw new Error(message);
1920
}
2021

2122
const json = await res.json();
22-
23-
return json;
23+
return json.defaultDocumentId;
2424
},
2525

2626
async getDefaultDocumentId(): Promise<null | string> {
@@ -34,11 +34,12 @@ export const DashboardApiClient = {
3434
{ method: 'GET', headers: { 'Content-Type': 'application/json', 'authorization': `Bearer ${login.accessToken}` } },
3535
);
3636

37-
const json = await res.json();
3837
if (!res.ok) {
39-
throw new Error(JSON.stringify(json, null, 2));
38+
const message = await res.text();
39+
throw new Error(message);
4040
}
4141

42+
const json = await res.json();
4243
return json.defaultDocumentId;
4344
},
4445

src/api/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ export const ApiClient = {
1616
{ method: 'POST', body, headers: { 'Content-Type': 'application/json' } }
1717
);
1818

19-
const json = await res.json();
2019
if (!res.ok) {
21-
throw new Error(JSON.stringify(json, null, 2));
20+
const message = await res.text();
21+
throw new Error(message);
2222
}
2323

24+
const json = await res.json();
2425
return json.results as unknown as PluginSearchResult;
2526
},
2627

0 commit comments

Comments
 (0)