Skip to content

Commit

Permalink
feat: SJIP-569 fix esClient close at any error and add field in biosp…
Browse files Browse the repository at this point in the history
…ecimen request report
  • Loading branch information
celinepelletier committed Oct 20, 2023
1 parent a3401d0 commit 872242e
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ export class ApplicationError extends Error {
}
}

export const reportGenerationErrorHandler = (err: any, es: Client): void => {
export const reportGenerationErrorHandler = (err: any): void => {
console.error(`An error occurs while generating the report`, err);
es && es.close();
throw new ApplicationError(err.message || err.details || 'An unknown error occurred.', INTERNAL_ERROR_STATUS_CODE);
};

Expand Down
2 changes: 1 addition & 1 deletion src/reports/biospecimen-data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const biospecimenDataReport = async (req: Request, res: Response): Promise<void>
// Generate the report
await generateReport(esClient, res, projectId, sqon, filename, normalizedConfigs, userId, accessToken);
} catch (err) {
reportGenerationErrorHandler(err, esClient);
reportGenerationErrorHandler(err);
}

console.timeEnd('biospecimen-data');
Expand Down
2 changes: 1 addition & 1 deletion src/reports/biospecimen-request/biospecimenRequestStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const biospecimenRequestStats = async (req: Request, res: Response): Promise<voi

res.send(biospecimenDatasByStudy);
} catch (err) {
reportGenerationErrorHandler(err, esClient);
reportGenerationErrorHandler(err);
}

console.timeEnd('biospecimenRequestStats');
Expand Down
2 changes: 2 additions & 0 deletions src/reports/biospecimen-request/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const generateStudyTab: (study_code: string) => SheetConfig = study_code
{ field: 'collection_sample_id', header: 'INCLUDE Collection ID' },
{ field: 'collection_sample_type', header: 'Collection Sample Type' },
{ field: 'container_id', header: 'Container ID' },
{ field: 'external_container_id', header: 'External Container ID' },
{ field: 'participant.external_id', header: 'External Participant ID' },
{ field: 'participant.participant_id', header: 'INCLUDE Participant ID' },
{ field: 'study.study_code', header: 'Study Code' },
Expand Down Expand Up @@ -65,6 +66,7 @@ export const wantedFields = [
'collection_sample_id',
'collection_sample_type',
'container_id',
'external_container_id',
'participant.external_id',
'participant.participant_id',
'study.study_code',
Expand Down
2 changes: 1 addition & 1 deletion src/reports/biospecimen-request/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const biospecimenRequest = async (req: Request, res: Response, _next: NextFuncti
res.sendFile(pathFileZip);
});
} catch (err) {
reportGenerationErrorHandler(err, esClient);
reportGenerationErrorHandler(err);
} finally {
console.timeEnd('biospecimenRequest');
}
Expand Down
2 changes: 1 addition & 1 deletion src/reports/clinical-data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const clinicalDataReport = async (req: Request, res: Response): Promise<void> =>
// Generate the report
await generateReport(esClient, res, projectId, sqon, filename, normalizedConfigs, userId, accessToken);
} catch (err) {
reportGenerationErrorHandler(err, esClient);
reportGenerationErrorHandler(err);
}

console.timeEnd('clinical-data');
Expand Down
2 changes: 1 addition & 1 deletion src/reports/family-clinical-data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const clinicalDataReport = async (req: Request, res: Response): Promise<void> =>
// Generate the report
await generateReport(esClient, res, projectId, familySqon, filename, normalizedConfigs, userId, accessToken);
} catch (err) {
reportGenerationErrorHandler(err, esClient);
reportGenerationErrorHandler(err);
}

console.timeEnd('family-clinical-data');
Expand Down
2 changes: 1 addition & 1 deletion src/reports/file-manifest/fileManifestStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const fileManifestStats = async (req: Request, res: Response): Promise<void> =>

res.send(filesInfosData);
} catch (err) {
reportGenerationErrorHandler(err, esClient);
reportGenerationErrorHandler(err);
}

console.timeEnd('getFileManifestStats');
Expand Down
2 changes: 1 addition & 1 deletion src/reports/file-manifest/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const fileManifestReport = async (req: Request, res: Response): Promise<void> =>
res.setHeader('Content-Disposition', `attachment; filename="${filename}.tsv"`);
res.sendFile(path);
} catch (err) {
reportGenerationErrorHandler(err, esClient);
reportGenerationErrorHandler(err);
}

console.timeEnd('fileManifestReport');
Expand Down

0 comments on commit 872242e

Please sign in to comment.