Handle raw response from idnot
This commit is contained in:
parent
463327e6a1
commit
09f12422cd
@ -227,38 +227,52 @@ 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));
|
||||
|
||||
if (userData.deleted) {
|
||||
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!);
|
||||
|
Loading…
x
Reference in New Issue
Block a user