From 78b920a18bbf3986dd9bb58c579874d7817a88ca Mon Sep 17 00:00:00 2001 From: dev4 Date: Thu, 18 Sep 2025 20:18:37 +0000 Subject: [PATCH] =?UTF-8?q?fix(idnot):=20mapper=20400->400=20et=20401->401?= =?UTF-8?q?=20(=C3=A9vite=20502)=20|=20ci:=20docker=5Ftag=3Dext?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/idnot/index.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/services/idnot/index.ts b/src/services/idnot/index.ts index 537bf28..9ca3f43 100644 --- a/src/services/idnot/index.ts +++ b/src/services/idnot/index.ts @@ -1,5 +1,6 @@ import fetch from 'node-fetch'; import { IdNotUser, ECivility, EOfficeStatus, EIdnotRole } from '../../types'; +import { ValidationError, UnauthorizedError, ExternalServiceError } from '../../types/errors'; export class IdNotService { static async exchangeCodeForTokens(code: string) { @@ -31,7 +32,13 @@ export class IdNotService { }); if (!response.ok) { - throw new Error(`Token exchange failed: ${response.status} ${response.statusText}`); + if (response.status === 400) { + throw new ValidationError('Invalid authorization code received from IdNot'); + } + if (response.status === 401) { + throw new UnauthorizedError('Invalid IdNot client credentials'); + } + throw new ExternalServiceError('IdNot', `Token exchange failed: ${response.status} ${response.statusText}`); } return response.json();