|
10 | 10 | */ |
11 | 11 |
|
12 | 12 | import type { MSTeamsAccessTokenProvider } from "./attachments/types.js"; |
| 13 | +import { createMSTeamsHttpError } from "./http-error.js"; |
13 | 14 | import { buildUserAgent } from "./user-agent.js"; |
14 | 15 |
|
15 | 16 | const GRAPH_ROOT = "https://graph.microsoft.com/v1.0"; |
@@ -50,8 +51,7 @@ export async function uploadToOneDrive(params: { |
50 | 51 | }); |
51 | 52 |
|
52 | 53 | if (!res.ok) { |
53 | | - const body = await res.text().catch(() => ""); |
54 | | - throw new Error(`OneDrive upload failed: ${res.status} ${res.statusText} - ${body}`); |
| 54 | + throw await createMSTeamsHttpError(res, "OneDrive upload failed"); |
55 | 55 | } |
56 | 56 |
|
57 | 57 | const data = (await res.json()) as { |
@@ -103,8 +103,7 @@ async function createSharingLink(params: { |
103 | 103 | }); |
104 | 104 |
|
105 | 105 | if (!res.ok) { |
106 | | - const body = await res.text().catch(() => ""); |
107 | | - throw new Error(`Create sharing link failed: ${res.status} ${res.statusText} - ${body}`); |
| 106 | + throw await createMSTeamsHttpError(res, "Create sharing link failed"); |
108 | 107 | } |
109 | 108 |
|
110 | 109 | const data = (await res.json()) as { |
@@ -198,8 +197,7 @@ export async function uploadToSharePoint(params: { |
198 | 197 | ); |
199 | 198 |
|
200 | 199 | if (!res.ok) { |
201 | | - const body = await res.text().catch(() => ""); |
202 | | - throw new Error(`SharePoint upload failed: ${res.status} ${res.statusText} - ${body}`); |
| 200 | + throw await createMSTeamsHttpError(res, "SharePoint upload failed"); |
203 | 201 | } |
204 | 202 |
|
205 | 203 | const data = (await res.json()) as { |
@@ -259,8 +257,7 @@ export async function getDriveItemProperties(params: { |
259 | 257 | ); |
260 | 258 |
|
261 | 259 | if (!res.ok) { |
262 | | - const body = await res.text().catch(() => ""); |
263 | | - throw new Error(`Get driveItem properties failed: ${res.status} ${res.statusText} - ${body}`); |
| 260 | + throw await createMSTeamsHttpError(res, "Get driveItem properties failed"); |
264 | 261 | } |
265 | 262 |
|
266 | 263 | const data = (await res.json()) as { |
@@ -371,8 +368,7 @@ async function getChatMembers(params: { |
371 | 368 | }); |
372 | 369 |
|
373 | 370 | if (!res.ok) { |
374 | | - const body = await res.text().catch(() => ""); |
375 | | - throw new Error(`Get chat members failed: ${res.status} ${res.statusText} - ${body}`); |
| 371 | + throw await createMSTeamsHttpError(res, "Get chat members failed"); |
376 | 372 | } |
377 | 373 |
|
378 | 374 | const data = (await res.json()) as { |
@@ -436,10 +432,7 @@ async function createSharePointSharingLink(params: { |
436 | 432 | ); |
437 | 433 |
|
438 | 434 | if (!res.ok) { |
439 | | - const respBody = await res.text().catch(() => ""); |
440 | | - throw new Error( |
441 | | - `Create SharePoint sharing link failed: ${res.status} ${res.statusText} - ${respBody}`, |
442 | | - ); |
| 435 | + throw await createMSTeamsHttpError(res, "Create SharePoint sharing link failed"); |
443 | 436 | } |
444 | 437 |
|
445 | 438 | const data = (await res.json()) as { |
|
0 commit comments