Skip to content

Commit

Permalink
Merge pull request #43 from Inist-CNRS/refactor/clean-up
Browse files Browse the repository at this point in the history
Clean-up and add missing mail
  • Loading branch information
AlasDiablo authored Jun 17, 2024
2 parents 00dc126 + e8dfac7 commit ada5c1f
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 19 deletions.
97 changes: 97 additions & 0 deletions ERROR_CODE_FR.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Liste des codes d'erreur qu'IA Factory peut renvoyer

Ceci est une liste qui tente d'expliquer toutes les causes liées à un code d'erreur.

## Erreur de type client

Liste les erreurs qui sont dues à un problème lié aux informations envoyées par l'utilisateur.

### Code 40

Ce code est utilisé quand le convertisseur ne peut pas convertir les données, car elles sont :

- incompatibles avec le convertisseur choisi,
- les données sont mal formatées ou corrompues,
- le champ cible est inapproprié ou incorrect

## Erreur de type serveur

Liste les erreurs qui sont dues à un problème du côté de l'application.

### Code 50

Le convertisseur a rencontré une erreur inattendue qui n'a pas été prévu et qui est irrécupérable.

Cette erreur englobe tout le convertisseur, une erreur est apparue à un moment non prévu
par les autres erreurs.

### Code 51

Erreur globale utilisée pour indiquer un problème lié au système de fichier.

Cette erreur peut arriver :

- quand le disque est plein,
- s'il y a des problèmes avec les accès disque.

### Code 52

L'appel du convertisseur a échoué dû a un problème réseau.

Ceci peut être dû à :

- convertisseur surchargé,
- convertisseur en maintenance,
- problème réseau (routage, proxy, etc.).

### Code 53

L'appel de l'enrichisseur a échoué dû a un problème réseau.

Ceci peut être dû à :

- enrichisseur est surchargé,
- enrichisseur en maintenance,
- problème réseau (routage, proxy, etc.).

### Code 54

L'enrichisseur a refusé l'enrichissement.

Ceci peut être dû à :

- problème réseau qui a causé une corruption des données,
- données à convertir corrompues.

### Code 55

L'enrichisseur a rencontré une erreur inattendue qui n'a pas été prévue et qui est irrécupérable.

Cette erreur englobe tout l'enrichisseur, une erreur est apparue à un moment non prévu
par les autres erreurs.

### Code 56

La récupération des résultats a rencontré une erreur inattendue qui n'a pas été prévue et qui est irrécupérable.

Cette erreur englobe tout la récupération des résultats, une erreur est apparue à un
moment non couvert par les autres erreurs.

### Code 57

La requête de récupération des résultats a échoué à cause d'un problème réseau.

Ceci peut être dû à :

- enrichisseur surchargé,
- enrichisseur en maintenance,
- problème réseau (routage, proxy, etc.).

### Code 58

L'enrichisseur a refusé la récupération des résultats.

Ceci peut être dû à :

- problème réseau qui a causé une corruption des données,
- les données liées ont expiré ou ne sont pas disponibles.
2 changes: 1 addition & 1 deletion tdm-be/config/production.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"isHttps": false
}
},
"mailFrom": "\"ISTEX IA Factory\" <no-reply@ia-factory.services.istex.fr>" ,
"mailFrom": "\"ISTEX IA Factory\" <no-reply@inist.fr>" ,
"smtp": {
"host": "{mail services host}",
"port": 1025,
Expand Down
2 changes: 1 addition & 1 deletion tdm-be/src/controller/data-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const getWrappers = async () => {
return wrappers;
};

//Route to access all wrapper available due to config set
//Route to access all wrappers available due to config set
router.get('/list', (req, res) => {
getWrappers().then((wrappers) => {
res.json(wrappers);
Expand Down
14 changes: 10 additions & 4 deletions tdm-be/src/lib/codes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const ERROR_CODE_WRAPPER_UNEXPECTED_ERROR = '50';
export const ERROR_MESSAGE_WRAPPER_UNEXPECTED_ERROR = `Le convertisseur a rencontré une erreur inattendue. Code d'erreur ${ERROR_CODE_WRAPPER_UNEXPECTED_ERROR}`;

export const ERROR_CODE_FILE_SYSTEM_ERROR = '51';
export const ERROR_MESSAGE_FILE_SYSTEM_ERROR = `Le convertisseur a rencontré une erreur inattendue. Code d'erreur ${ERROR_CODE_FILE_SYSTEM_ERROR}`;
export const ERROR_MESSAGE_FILE_SYSTEM_ERROR = `Le traitement a rencontré une erreur inattendue. Code d'erreur ${ERROR_CODE_FILE_SYSTEM_ERROR}`;

export const ERROR_CODE_WRAPPER_UNREACHABLE_ERROR = '52';
export const ERROR_MESSAGE_WRAPPER_UNREACHABLE_ERROR = `Le convertisseur a rencontré une erreur inattendue. Code d'erreur ${ERROR_CODE_WRAPPER_UNREACHABLE_ERROR}`;
Expand All @@ -18,8 +18,14 @@ export const ERROR_MESSAGE_ENRICHMENT_UNREACHABLE_ERROR = `L'enrichissement a re
export const ERROR_CODE_ENRICHMENT_PAYLOAD_NOT_ACCEPTED_ERROR = '54';
export const ERROR_MESSAGE_ENRICHMENT_PAYLOAD_NOT_ACCEPTED_ERROR = `L'enrichissement a refusé le traitement. Code d'erreur ${ERROR_CODE_ENRICHMENT_PAYLOAD_NOT_ACCEPTED_ERROR}`;

export const ERROR_CODE_ENRICHMENT_UNEXPECTED_ERROR = '54';
export const ERROR_MESSAGE_ENRICHMENT_UNEXPECTED_ERROR = `Le enrichissement a rencontré une erreur inattendue. Code d'erreur ${ERROR_CODE_ENRICHMENT_UNEXPECTED_ERROR}`;
export const ERROR_CODE_ENRICHMENT_UNEXPECTED_ERROR = '55';
export const ERROR_MESSAGE_ENRICHMENT_UNEXPECTED_ERROR = `L'enrichissement a rencontré une erreur inattendue. Code d'erreur ${ERROR_CODE_ENRICHMENT_UNEXPECTED_ERROR}`;

export const ERROR_CODE_ENRICHMENT_HOOK_UNEXPECTED_ERROR = '55';
export const ERROR_CODE_ENRICHMENT_HOOK_UNEXPECTED_ERROR = '56';
export const ERROR_MESSAGE_ENRICHMENT_HOOK_UNEXPECTED_ERROR = `La récuperation des données a rencontré une erreur inattendue. Code d'erreur ${ERROR_CODE_ENRICHMENT_HOOK_UNEXPECTED_ERROR}`;

export const ERROR_CODE_ENRICHMENT_HOOK_UNREACHABLE_ERROR = '57';
export const ERROR_MESSAGE_ENRICHMENT_HOOK_UNREACHABLE_ERROR = `La récuperation des données a rencontré une erreur inattendue. Code d'erreur ${ERROR_CODE_ENRICHMENT_HOOK_UNREACHABLE_ERROR}`;

export const ERROR_CODE_ENRICHMENT_HOOK_PAYLOAD_NOT_ACCEPTED_ERROR = '58';
export const ERROR_MESSAGE_ENRICHMENT_HOOK_PAYLOAD_NOT_ACCEPTED_ERROR = `La récuperation des données a été refusé. Code d'erreur ${ERROR_CODE_ENRICHMENT_HOOK_PAYLOAD_NOT_ACCEPTED_ERROR}`;
4 changes: 4 additions & 0 deletions tdm-be/src/templates/processing-error.njk
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Vous trouverez dans ce mail un rapport d'erreur du traitement {{ processingId }}

{{ errorMessage }}

Vous pouvez retrouver une description de la cause possible de l'erreur sur le lien ci-dessous :

https://github.com/Inist-CNRS/tdm-factory/blob/main/ERROR_CODE_FR.md

Voici un récapitulatif des informations liées à ce traitement :

- Id du traitement : {{ processingId }}
Expand Down
4 changes: 3 additions & 1 deletion tdm-be/src/worker/enrichment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ const catchEnrichment = (processingId: string) => {
return;
}
errorEmail(processing, ERROR_MESSAGE_ENRICHMENT_UNEXPECTED_ERROR);
} catch (ignored) {}
} catch (ignored) {
/* empty */
}
});
};

Expand Down
52 changes: 43 additions & 9 deletions tdm-be/src/worker/enrichmentHook.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { ERROR_MESSAGE_ENRICHMENT_HOOK_UNEXPECTED_ERROR } from '~/lib/codes';
import {
ERROR_MESSAGE_ENRICHMENT_HOOK_PAYLOAD_NOT_ACCEPTED_ERROR,
ERROR_MESSAGE_ENRICHMENT_HOOK_UNEXPECTED_ERROR,
ERROR_MESSAGE_ENRICHMENT_HOOK_UNREACHABLE_ERROR,
ERROR_MESSAGE_FILE_SYSTEM_ERROR,
} from '~/lib/codes';
import environment from '~/lib/config';
import crash from '~/lib/crash';
import { sendErrorMail, sendFinishedMail } from '~/lib/email';
import { downloadFile, randomFileName } from '~/lib/files';
import logger, { workerLogger } from '~/lib/logger';
import { workerLogger } from '~/lib/logger';
import { errorEmail } from '~/lib/utils';
import dynamicConfig from '~/model/DynamicConfig';
import { findProcessing, updateProcessing } from '~/model/ProcessingModel';
Expand Down Expand Up @@ -41,7 +46,7 @@ const enrichmentHookSuccess = async (processingId: string) => {
// Find the processing in the cache db
const initialProcessing = findProcessing(processingId);

// Check if the processing exist
// Check if the processing exists
if (!initialProcessing) {
error(processingId, 'Enrichment-Hook initial processing is undefined');
// Send error the global catcher because this is normally impossible
Expand Down Expand Up @@ -75,7 +80,7 @@ const enrichmentHookSuccess = async (processingId: string) => {
return enrichmentUrl.includes(entry.url);
});

// Check if enrichment entry exist
// Check if enrichment entry exists
if (!enrichmentEntry || !enrichmentEntry.url || !enrichmentEntry.retrieveUrl) {
error(processingId, 'Enrichment-Hook config dos not contain the enrichment url');
// Send error the global catcher because this is normally impossible
Expand All @@ -94,7 +99,17 @@ const enrichmentHookSuccess = async (processingId: string) => {
} catch (e) {
const message = 'Impossible to contact enrichment-hook api';
error(processingId, message);
// TODO Send an error email
sendErrorMail({
email,
data: {
processingId: initialProcessing.id,
originalName: initialProcessing.originalName,
wrapper: initialProcessing.wrapper as string,
wrapperParam: initialProcessing.wrapperParam as string,
enrichment: initialProcessing.enrichment as string,
errorMessage: ERROR_MESSAGE_ENRICHMENT_HOOK_UNREACHABLE_ERROR,
},
}).then(undefined);
crash(e, message, initialProcessing);
return;
}
Expand All @@ -105,7 +120,17 @@ const enrichmentHookSuccess = async (processingId: string) => {
// Check if we receive a non 200 status code
if (response.status !== 200) {
error(processingId, 'Enrichment-hook api return an non 200 status');
// TODO Send an error email
sendErrorMail({
email,
data: {
processingId: initialProcessing.id,
originalName: initialProcessing.originalName,
wrapper: initialProcessing.wrapper as string,
wrapperParam: initialProcessing.wrapperParam as string,
enrichment: initialProcessing.enrichment as string,
errorMessage: ERROR_MESSAGE_ENRICHMENT_HOOK_PAYLOAD_NOT_ACCEPTED_ERROR,
},
}).then(undefined);
return;
}

Expand All @@ -120,15 +145,24 @@ const enrichmentHookSuccess = async (processingId: string) => {
} catch (e) {
const message = "Can't write tmp file";
error(processingId, message);
// TODO Send an error email
sendErrorMail({
email,
data: {
processingId: initialProcessing.id,
originalName: initialProcessing.originalName,
wrapper: initialProcessing.wrapper as string,
wrapperParam: initialProcessing.wrapperParam as string,
enrichment: initialProcessing.enrichment as string,
errorMessage: ERROR_MESSAGE_FILE_SYSTEM_ERROR,
},
}).then(undefined);
crash(e, message, initialProcessing);
return;
}

const resultUrl = `${
environment.hosts.external.isHttps ? 'https' : 'http'
}://${environment.hosts.external.host}/downloads/${finalFileName}`;
logger.info('mail sent to smtp');

sendFinishedMail({
email,
Expand Down Expand Up @@ -162,7 +196,7 @@ const enrichmentHookFailure = async (processingId: string) => {
// Find the processing in the cache db
const initialProcessing = findProcessing(processingId);

// Check if the processing exist
// Check if the processing exists
if (!initialProcessing) {
error(processingId, 'Enrichment-Hook initial processing is undefined');
// Send error the global catcher because this is normally impossible
Expand Down
2 changes: 0 additions & 2 deletions tdm-be/src/worker/fields/csvFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ const csvFields = async (fileName: string): Promise<string[]> => {
timeout: 600000,
});

logger.info(Buffer.from(response.data, 'binary').toString('utf8'));

const json = JSON.parse(Buffer.from(response.data, 'binary').toString('utf8')) as Array<{
value: string;
}>;
Expand Down
4 changes: 3 additions & 1 deletion tdm-be/src/worker/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ const catchWrapper = (processingId: string) => {
return;
}
errorEmail(processing, ERROR_MESSAGE_WRAPPER_UNEXPECTED_ERROR);
} catch (ignored) {}
} catch (ignored) {
/* empty */
}
});
};

Expand Down

0 comments on commit ada5c1f

Please sign in to comment.