ci: docker_tag=ext fix(back): map JSON parse errors to 400; bump 1.0.2; docs/tests updated
All checks were successful
build-and-push-ext / build_push (push) Successful in 24s
All checks were successful
build-and-push-ext / build_push (push) Successful in 24s
This commit is contained in:
parent
78b920a18b
commit
bd042533b2
11
CHANGELOG.md
11
CHANGELOG.md
@ -3,3 +3,14 @@
|
||||
- IdNot: l’endpoint d’authentification accepte désormais le code en POST `/api/v1/idnot/auth` avec `{ code }` dans le corps.
|
||||
- Handler compatible params/body, recommandation: body JSON.
|
||||
- Rappel déploiement: image Docker consommée par `lecoffre_node` via tag `ext`.
|
||||
|
||||
## v1.0.2
|
||||
|
||||
- Erreurs de parsing JSON (body-parser) désormais mappées en 400 au lieu de 500 via `error-handler`.
|
||||
- Clarification des statuts attendus:
|
||||
- 400: JSON invalide ou code d'auth invalide
|
||||
- 401: non autorisé (ex: email manquant)
|
||||
- 403: utilisateur non rattaché à une étude
|
||||
- 5xx: erreurs internes ou partenaires (non applicatives)
|
||||
- Documentation et tests mis à jour pour couvrir “JSON invalide -> 400”.
|
||||
- CI: utiliser `ci: docker_tag=ext` pour builder/pusher l’image.
|
||||
|
@ -28,6 +28,14 @@ Analyse synthétique de `lecoffre-back-mini` (Express + TypeScript).
|
||||
- L’endpoint d’authentification accepte désormais le code en POST corps JSON sur `/api/v1/idnot/auth` (au lieu d’un segment d’URL).
|
||||
- Le handler supporte à la fois `req.params.code` et `req.body.code` pour compatibilité, mais l’usage recommandé est `req.body.code`.
|
||||
|
||||
### Gestion des erreurs HTTP
|
||||
- `400`:
|
||||
- JSON invalide (erreur de parsing du corps) → mappé explicitement par `errorHandler`
|
||||
- Code d’autorisation IdNot invalide (ValidationError)
|
||||
- `401`: non autorisé (ex: email manquant)
|
||||
- `403`: utilisateur non rattaché à une étude (ForbiddenError)
|
||||
- `5xx`: erreurs internes ou partenaires (ExternalServiceError)
|
||||
|
||||
### Dépendances clés
|
||||
- **HTTP**: `express`, `cors`
|
||||
- **Infra**: `pg`, `dotenv`
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "lecoffre-back-mini",
|
||||
"version": "1.0.1",
|
||||
"version": "1.0.2",
|
||||
"description": "Mini serveur avec une route /api/ping",
|
||||
"main": "dist/server.js",
|
||||
"scripts": {
|
||||
|
@ -78,6 +78,30 @@ export const errorHandler = (
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle JSON parsing errors (body-parser SyntaxError)
|
||||
if (
|
||||
error.name === 'SyntaxError' ||
|
||||
(typeof (error as any)?.type === 'string' && (error as any).type === 'entity.parse.failed')
|
||||
) {
|
||||
const appError = new AppError(
|
||||
ErrorCode.VALIDATION_ERROR,
|
||||
'JSON invalide',
|
||||
400,
|
||||
true,
|
||||
undefined,
|
||||
requestId
|
||||
);
|
||||
|
||||
Logger.error('JSON parse error', {
|
||||
requestId,
|
||||
originalError: (error as any)?.message,
|
||||
stack: (error as any)?.stack
|
||||
});
|
||||
|
||||
res.status(400).json(appError.toJSON());
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle database errors
|
||||
if (error.message?.includes('database') || error.message?.includes('connection')) {
|
||||
const appError = new AppError(
|
||||
|
@ -17,4 +17,5 @@ Axes de tests pour `lecoffre-back-mini` (sans exemples d’implémentation).
|
||||
|
||||
### Auth IdNot
|
||||
- Vérifier POST `/api/v1/idnot/auth` avec un code long dans le corps JSON (`{ code }`) retourne un statut applicatif (4xx/5xx) mais pas 502.
|
||||
- Vérifier qu’un corps JSON invalide (ex: JSON mal formé) renvoie `400`.
|
||||
- Vérifier qu’un GET/POST avec segment d’URL trop long n’est plus utilisé par le front.
|
||||
|
Loading…
x
Reference in New Issue
Block a user