From b96720c0af6d524511c65e7254afb7104125d153 Mon Sep 17 00:00:00 2001 From: Sosthene Date: Tue, 22 Jul 2025 14:48:04 +0200 Subject: [PATCH] Handle raw response from idnot --- .../common/IdNotService/IdNotService.ts | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/services/common/IdNotService/IdNotService.ts b/src/services/common/IdNotService/IdNotService.ts index 4e22695f..44a63573 100644 --- a/src/services/common/IdNotService/IdNotService.ts +++ b/src/services/common/IdNotService/IdNotService.ts @@ -227,21 +227,29 @@ export default class IdNotService extends BaseService { key: this.variables.IDNOT_API_KEY, }); - let userData: IRattachementData; + let userRawData: Response; try { - userData = (await ( - await fetch( + userRawData = await fetch( `${this.variables.IDNOT_API_BASE_URL}/api/pp/v2/rattachements/${user.idNot}_${user.office_membership!.idNot}?` + searchParams, { method: "GET", }, ) - ).json()) as IRattachementData; } catch (error) { console.error(`Error fetching user data for ${user.uid}: ${error}`); return; } + + if (userRawData.status === 404) { + console.error(`User ${user.uid} not found in idnot`); + return; + } else if (userRawData.status !== 200) { + console.error(`Error fetching user data for ${user.uid}: ${userRawData.status} - ${userRawData.statusText}`); + return; + } + + let userData = (await userRawData.json()) as IRattachementData; console.log("Got userData from idnot", JSON.stringify(userData)); @@ -249,16 +257,22 @@ export default class IdNotService extends BaseService { let rattachements: any; try { - rattachements = (await ( - await fetch(`${this.variables.IDNOT_API_BASE_URL}/api/pp/v2/personnes/${user.idNot}/rattachements?deleted=false` + searchParams, { - method: "GET", - }) - ).json()) as any; + rattachements = await fetch(`${this.variables.IDNOT_API_BASE_URL}/api/pp/v2/personnes/${user.idNot}/rattachements?deleted=false` + searchParams, { + method: "GET", + }); } catch (error) { console.error("Error fetching rattachements", error); return; } + if (rattachements.status === 404) { + console.error(`User ${user.uid} not found in idnot`); + return; + } else if (rattachements.status !== 200) { + console.error(`Error fetching rattachements for ${user.uid}: ${rattachements.status} - ${rattachements.statusText}`); + return; + } + if (rattachements.totalResultCount === 0) { console.warn("User has no valid rattachements", user.uid); await this.userService.updateCheckedAt(user.uid!);