Skip to content

Commit

Permalink
remove catch: logs are from shared-routes
Browse files Browse the repository at this point in the history
  • Loading branch information
celineung committed Feb 12, 2025
1 parent a271260 commit cc466f5
Showing 1 changed file with 37 additions and 66 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Bottleneck from "bottleneck";
import { RomeDto, SearchResultDto, SiretDto, castError } from "shared";
import { RomeDto, SearchResultDto, SiretDto } from "shared";
import { HttpClient } from "shared-routes";
import { createLogger } from "../../../../utils/logger";
import { FranceTravailGateway } from "../../../convention/ports/FranceTravailGateway";
import { WithCache } from "../../../core/caching-gateway/port/WithCache";
import {
Expand All @@ -21,8 +20,6 @@ const lbbMaxQueryPerSeconds = 1;

const lbbV2App = "api_labonneboitev2";

Check failure

Code scanning / CodeQL

Hard-coded credentials Critical

The hard-coded value "api_labonneboitev2" is used as
authorization header
.
The hard-coded value "api_labonneboitev2" is used as
authorization header
.

const logger = createLogger(__filename);

export class HttpLaBonneBoiteGateway implements LaBonneBoiteGateway {
#limiter = new Bottleneck({
reservoir: lbbMaxQueryPerSeconds,
Expand Down Expand Up @@ -84,47 +81,31 @@ export class HttpLaBonneBoiteGateway implements LaBonneBoiteGateway {
});

return this.#limiter.schedule(() =>
cachedGetLbbResults(searchCompaniesParams)
.then((results) => {
return results
.map(
(props: LaBonneBoiteApiResultV2Props) =>
new LaBonneBoiteCompanyDto(props),
)
.filter((result) => result.isCompanyRelevant())
.map((result) =>
result.toSearchResult(
{
romeCode: searchCompaniesParams.romeCode,
romeLabel: searchCompaniesParams.romeLabel,
},
{
lat: searchCompaniesParams.lat,
lon: searchCompaniesParams.lon,
},
),
)
.filter((result) =>
result.distance_m
? result.distance_m <= searchCompaniesParams.distanceKm * 1000
: true,
);
})
.catch((error) => {
logger.error({
error: castError(error),
message: "searchCompanies_error",
searchLBB: {
distanceKm: searchCompaniesParams.distanceKm,
lat: searchCompaniesParams.lat,
lon: searchCompaniesParams.lon,
romeCode: searchCompaniesParams.romeCode,
romeLabel: searchCompaniesParams.romeLabel,
nafCodes: searchCompaniesParams.nafCodes,
},
});
return [];
}),
cachedGetLbbResults(searchCompaniesParams).then((results) => {
return results
.map(
(props: LaBonneBoiteApiResultV2Props) =>
new LaBonneBoiteCompanyDto(props),
)
.filter((result) => result.isCompanyRelevant())
.map((result) =>
result.toSearchResult(
{
romeCode: searchCompaniesParams.romeCode,
romeLabel: searchCompaniesParams.romeLabel,
},
{
lat: searchCompaniesParams.lat,
lon: searchCompaniesParams.lon,
},
),
)
.filter((result) =>
result.distance_m
? result.distance_m <= searchCompaniesParams.distanceKm * 1000
: true,
);
}),
);
}

Expand Down Expand Up @@ -157,28 +138,18 @@ export class HttpLaBonneBoiteGateway implements LaBonneBoiteGateway {
},
});
return this.#limiter.schedule(async () =>
cachedGetLbbResult(siret)
.then((result) => {
const item = result
.map(
(props: LaBonneBoiteApiResultV2Props) =>
new LaBonneBoiteCompanyDto(props),
)
.filter((result) => result.isCompanyRelevant())
.map((result) => result.toSearchResult(romeDto))
.at(0);
cachedGetLbbResult(siret).then((result) => {
const item = result
.map(
(props: LaBonneBoiteApiResultV2Props) =>
new LaBonneBoiteCompanyDto(props),
)
.filter((result) => result.isCompanyRelevant())
.map((result) => result.toSearchResult(romeDto))
.at(0);

return item ?? null;
})
.catch((error) => {
logger.error({
error: castError(error),
message: "fetchCompanyBySiret_error",
siret,
romeLabel: romeDto.romeLabel,
});
throw error;
}),
return item ?? null;
}),
);
}

Expand Down

0 comments on commit cc466f5

Please sign in to comment.