diff --git a/server/src/http/server.ts b/server/src/http/server.ts index 029db1b64..34f3b8d28 100644 --- a/server/src/http/server.ts +++ b/server/src/http/server.ts @@ -403,21 +403,24 @@ function setupRoutes(app: Application) { ["/api/v3/dossiers-apprenants"], requireBearerAuthentication(), async (req, res, next) => { - const organisme = await getOrganismeByAPIKey(res.locals.token, req.query); + try { + const organisme = await getOrganismeByAPIKey(res.locals.token, req.query); - (req.user as any) = { - source: SOURCE_APPRENANT.ERP, - source_organisme_id: organisme._id.toString(), - }; - - Sentry.setUser({ - segment: "bearer", - ip_address: req.ip, - id: `organisme-${organisme._id.toString()}`, - username: `organisme: ${organisme.siret} / ${organisme.uai}`, - }); + (req.user as any) = { + source: SOURCE_APPRENANT.ERP, + source_organisme_id: organisme._id.toString(), + }; - next(); + Sentry.setUser({ + segment: "bearer", + ip_address: req.ip, + id: `organisme-${organisme._id.toString()}`, + username: `organisme: ${organisme.siret} / ${organisme.uai}`, + }); + next(); + } catch (err) { + next(err); + } }, dossierApprenantRouter() );