fix(idnot): mapper 400->400 et 401->401 (évite 502) | ci: docker_tag=ext
All checks were successful
build-and-push-ext / build_push (push) Successful in 15s

This commit is contained in:
dev4 2025-09-18 20:18:37 +00:00
parent 4c3848ceea
commit 78b920a18b

View File

@ -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();