Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(data subvention): try to use id rna #1484

Merged
merged 2 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions clients/api-data-subvention/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { HttpNotFound } from '#clients/exceptions';
import routes from '#clients/routes';
import constants from '#models/constants';
import { ISubvention, ISubventions } from '#models/subventions/association';
import { Siren } from '#utils/helpers';
import { IdRna, Siren } from '#utils/helpers';
import { httpGet } from '#utils/network';

/**
* Data Subvention
* https://api.datasubvention.beta.gouv.fr/
*/
export const clientApiDataSubvention = async (
siren: Siren
siren: Siren | IdRna | string
): Promise<ISubventions> => {
const route = routes.apiDataSubvention.grants(siren);
const data = await httpGet<any>(route, {
Expand Down
2 changes: 1 addition & 1 deletion components/subventions-association-section/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export const SubventionsAssociationSection: React.FC<{
subventions={subventions}
siren={uniteLegale.siren}
/>
<div className="layout-right">
<div className="layout-right" style={{ marginBottom: '20px' }}>
<ul className="fr-btns-group fr-btns-group--inline-md fr-btns-group--center">
<li style={{ marginRight: '10px' }}>
<Select
Expand Down
49 changes: 34 additions & 15 deletions models/subventions/association/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
IAPINotRespondingError,
} from '#models/api-not-responding';
import { getUniteLegaleFromSlug } from '#models/core/unite-legale';
import { FetchRessourceException } from '#models/exceptions';
import logErrorInSentry from '#utils/sentry';
import { FetchRessourceException, Information } from '#models/exceptions';
import logErrorInSentry, { logInfoInSentry } from '#utils/sentry';

export type ISubventions = ISubvention[];

Expand All @@ -26,24 +26,43 @@ export const getSubventionsAssociationFromSlug = async (
isBot: false,
});

const { siren } = uniteLegale;

const {
siren,
association: { idAssociation },
} = uniteLegale;
try {
return await clientApiDataSubvention(siren);
} catch (e: any) {
if (e instanceof HttpNotFound) {
return APINotRespondingFactory(EAdministration.DJEPVA, 404);
} else if (!idAssociation) {
return APINotRespondingFactory(EAdministration.DJEPVA, 500);
} else {
try {
const result = await clientApiDataSubvention(idAssociation);
logInfoInSentry(
new Information({
name: 'DataSubvention',
message: 'Fallback worked for data subvention',
})
);
return result;
} catch (e) {
if (e instanceof HttpNotFound) {
return APINotRespondingFactory(EAdministration.DJEPVA, 404);
}
logErrorInSentry(
new FetchRessourceException({
ressource: 'DataSubvention',
cause: e,
context: {
siren,
},
administration: EAdministration.DJEPVA,
})
);
return APINotRespondingFactory(EAdministration.DJEPVA, 500);
}
}
logErrorInSentry(
new FetchRessourceException({
ressource: 'DataSubvention',
cause: e,
context: {
siren,
},
administration: EAdministration.DJEPVA,
})
);
return APINotRespondingFactory(EAdministration.DJEPVA, 500);
}
};
Loading