From ae8e63371661d8dba296724857de3277af939121 Mon Sep 17 00:00:00 2001 From: Morgan <33722304+ThyMinimalDev@users.noreply.github.com> Date: Tue, 19 Aug 2025 15:10:28 +0300 Subject: [PATCH] fix: correct impossible logical condition in Office365 calendar error handling #23151 (#23185) --- .../office365calendar/lib/CalendarService.ts | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/app-store/office365calendar/lib/CalendarService.ts b/packages/app-store/office365calendar/lib/CalendarService.ts index 04626103f4..cb9b6c18a4 100644 --- a/packages/app-store/office365calendar/lib/CalendarService.ts +++ b/packages/app-store/office365calendar/lib/CalendarService.ts @@ -661,22 +661,30 @@ export default class Office365CalendarService implements Calendar { ); }; - private handleErrorJsonOffice365Calendar = (response: Response): Promise => { + private async handleErrorJsonOffice365Calendar(response: Response): Promise { if (response.headers.get("content-encoding") === "gzip") { return response.text(); } if (response.status === 204) { - return new Promise((resolve) => resolve({} as Type)); + return {} as Type; } - if (!response.ok && response.status < 200 && response.status >= 300) { - response.json().then(console.log); - throw Error(response.statusText); + if (!response.ok) { + let errorBody: string | object; + try { + errorBody = await response.json(); + } catch (e) { + errorBody = await response.text(); + } + this.log.error( + `handleErrorJsonOffice365Calendar: Office365 API request failed with status ${response.status}`, + errorBody + ); } return response.json(); - }; + } async getMainTimeZone(): Promise { try {