-
- + } /> } /> @@ -121,7 +113,7 @@ export const TeamBackOffice = () => { /> } + element={} /> } /> } /> @@ -131,7 +123,13 @@ export const TeamBackOffice = () => {
); } else { - return
Error while fetching team
+ + const e = error?.message || currentTeam?.error + + toast.error(e) + + return null; //todo: [#609] display a better error + } }; diff --git a/daikoku/javascript/src/components/backoffice/apis/TeamApi.tsx b/daikoku/javascript/src/components/backoffice/apis/TeamApi.tsx index 43f7a91e7..5658dfd92 100644 --- a/daikoku/javascript/src/components/backoffice/apis/TeamApi.tsx +++ b/daikoku/javascript/src/components/backoffice/apis/TeamApi.tsx @@ -224,9 +224,7 @@ export const TeamApi = (props: TeamBackOfficeProps<{ creation: boolean }>) => { const tab: string = params.tab || 'infos'; - if (tenant.creationSecurity && !props.currentTeam.apisCreationPermission) { - dispatch(setError({ error: { status: 403, message: 'Creation security enabled' } })); - } + useEffect(() => { if (api) { @@ -282,6 +280,11 @@ export const TeamApi = (props: TeamBackOfficeProps<{ creation: boolean }>) => { } }, [api]); + if (tenant.creationSecurity && !props.currentTeam.apisCreationPermission) { + toast.error(translate('creation.security.enabled.message')) + return null; + } + if (!newApi && apiRequest.isLoading) { return } else if (newApi || (apiRequest.data && !isError(apiRequest.data))) { diff --git a/daikoku/javascript/src/components/frontend/FrontOffice.tsx b/daikoku/javascript/src/components/frontend/FrontOffice.tsx index 278442409..f889da75f 100644 --- a/daikoku/javascript/src/components/frontend/FrontOffice.tsx +++ b/daikoku/javascript/src/components/frontend/FrontOffice.tsx @@ -1,8 +1,8 @@ -import React from 'react'; -import { IState, IStateError } from '../../types'; export const FrontOffice = (props: { children: JSX.Element }) => { - const error = useSelector(s => s.error) + // const error = useSelector(s => s.error) - return <>{!error.status && props.children}; + //todo: [#609] display a better error + + return <>{props.children}; }; \ No newline at end of file diff --git a/daikoku/javascript/src/components/frontend/api/ApiHome.tsx b/daikoku/javascript/src/components/frontend/api/ApiHome.tsx index 7237b33c5..cb2aed278 100644 --- a/daikoku/javascript/src/components/frontend/api/ApiHome.tsx +++ b/daikoku/javascript/src/components/frontend/api/ApiHome.tsx @@ -200,24 +200,6 @@ export const ApiHome = ({ } }, [subscriptions, myTeams]); - // type TTeamGQL = { - // name: string - // _humanReadableId: string - // _id: string - // type: TeamType - // apiKeyVisibility: TeamPermission - // apisCreationPermission: boolean - // verified: boolean - // users: Array<{ - // user: { - // userId: string - // } - // teamPermission: TeamPermission - // }> - // } - // type TMyTeamsGQL = { - // myTeams: Array - // } const updateSubscriptions = (apiId: string) => { //FIXME: handle case if appolo client is not setted if (!client) { @@ -238,7 +220,7 @@ export const ApiHome = ({ }, ]) => { if (isError(api)) { - dispatch(setError({ error: { status: 404, message: api.error } })); + toast.error(api.error) //FIXME [#609] better error management } else { setApi(api); setSubscriptions(subscriptions); diff --git a/daikoku/javascript/src/components/utils/Errors.tsx b/daikoku/javascript/src/components/utils/Errors.tsx deleted file mode 100644 index 0d7d5556d..000000000 --- a/daikoku/javascript/src/components/utils/Errors.tsx +++ /dev/null @@ -1,83 +0,0 @@ -import { useContext, useEffect, useState } from 'react'; -import { useDispatch } from 'react-redux'; -import { useSelector } from 'react-redux'; -import { Link, useNavigate } from 'react-router-dom'; -import { I18nContext } from '../../contexts/i18n-context'; -import { unsetError } from '../../contexts'; - -import { IState, IStateError, ITenant } from '../../types'; - -const getErrorLabel = (status: any, error: any) => { - // if (status) console.log(status, error); - if (status === 400) { - return 'Bad Request'; - } else if (status === 401) { - return error.message || 'Forbidden'; - } else if (status === 403) { - return error.message || 'Unauthorized'; - } else if (status === 404) { - return error.message || 'Page Not Found'; - } else if (status > 399 && status < 500) { - return 'Client Error'; - } else if (status > 499 && status < 600) { - return error.message || 'Server Error'; - } else { - return null; - } -}; - -export const Error = () => { - const navigate = useNavigate(); - const { translate } = useContext(I18nContext); - - const [label, setLabel] = useState(); - - - const error = useSelector(s => s.error); - const tenant = useSelector(s => s.context.tenant); - const dispatch = useDispatch(); - - useEffect(() => { - setLabel(getErrorLabel(error.status, error)); - if (error?.status) { - document.title = `${tenant.title} - ${translate('Error')}`; - } - }, [error, label]); - - if (!label || !error) { - return null; - } - - return ( -
-
-
-
-

{error.status}

-

{label}

-
-
- { - dispatch(unsetError()); - }} - > - {translate('Go home')} - - -
-
-
-
- ); -}; diff --git a/daikoku/javascript/src/components/utils/index.ts b/daikoku/javascript/src/components/utils/index.ts index da0550eae..3c1a294e6 100644 --- a/daikoku/javascript/src/components/utils/index.ts +++ b/daikoku/javascript/src/components/utils/index.ts @@ -7,7 +7,6 @@ export * from './Spinner'; export * from './AvatarChooser'; export * from './PaginatedComponent'; export * from './AvatarWithAction'; -export * from './Errors'; export * from './Option'; export * from './permissions'; export * from './Footer'; diff --git a/daikoku/javascript/src/locales/en/translation.json b/daikoku/javascript/src/locales/en/translation.json index 0f0fce4cd..c9cbb4309 100644 --- a/daikoku/javascript/src/locales/en/translation.json +++ b/daikoku/javascript/src/locales/en/translation.json @@ -1374,5 +1374,6 @@ "apisubscription.lastUsage.label": "Last usage", "N/A": "N/A", "semver.error.message": "Can't create version with special characters : %s", - "version.creation.success.message": "New version of api created successfully" + "version.creation.success.message": "New version of api created successfully", + "error.message.creation.security.enabled": "You're not authorized to create API, please contact your administrator." } \ No newline at end of file diff --git a/daikoku/javascript/src/locales/fr/translation.json b/daikoku/javascript/src/locales/fr/translation.json index 071ac08d9..0836740b7 100644 --- a/daikoku/javascript/src/locales/fr/translation.json +++ b/daikoku/javascript/src/locales/fr/translation.json @@ -1378,5 +1378,6 @@ "apisubscription.lastUsage.label": "Dernier usage", "N/A": "N/A", "semver.error.message": "Une version ne peut pas être créée avec des caractère spéciaux : %s", - "version.creation.success.message": "La nouvelle version de l'API a été créée avec succès" + "version.creation.success.message": "La nouvelle version de l'API a été créée avec succès", + "error.message.creation.security.enabled": "Vous n'êtes pas authorisé a créer d'API, merci de contacter votre administrateur." } \ No newline at end of file diff --git a/daikoku/javascript/src/services/customize.ts b/daikoku/javascript/src/services/customize.ts index 3c7504c27..41547dc8d 100644 --- a/daikoku/javascript/src/services/customize.ts +++ b/daikoku/javascript/src/services/customize.ts @@ -1,18 +1,19 @@ -import { SET_ERROR } from '../contexts'; import queryString from 'query-string'; +import { toast } from 'sonner'; export function customizeFetch(store: any) { let willRedirect = false; (window as any).old_fetch = window.fetch; window.fetch = (...args) => { - const dispatchError = (response: any) => - response.json().then((error: any) => { - store.dispatch({ - type: SET_ERROR, - error: { status: response.status, message: error.error, args, response: error }, - }); - return Promise.reject(error); - }); + // const dispatchError = (response: any) => + // response.json() + // .then((error: any) => { + // store.dispatch({ + // type: SET_ERROR, + // error: { status: response.status, message: error.error, args, response: error }, + // }); + // return Promise.reject(error); + // }); const query = queryString.parse(window.location.search); const url = args[0]; @@ -28,27 +29,29 @@ export function customizeFetch(store: any) { newArgs.shift(); newArgs = [newUrl, ...newArgs]; - return (window as any).old_fetch(...newArgs).then((r: any) => { - const status = r.status; - if (r.redirected && r.url.indexOf('/auth/') > -1) { - if (willRedirect === false) { - willRedirect = true; - // redirect(); + return (window as any).old_fetch(...newArgs) + .then((r: any) => { + const status = r.status; + if (r.redirected && r.url.indexOf('/auth/') > -1) { + if (willRedirect === false) { + willRedirect = true; + // redirect(); + } + } else if (status > 199 && status < 300) { + // nothing to do yet + } else if (status > 299 && status < 400) { + // nothing to do yet + } else if (status === 409) { + // toast.error('Conflict', 'The resource already exists'); + } else if (status === 404) { + // nothing to do yet + } else if (status >= 500 && status < 600) { + toast.error(r.error) //TODO [#609] + return r + } else { + // nothing to do yet } - } else if (status > 199 && status < 300) { - // nothing to do yet - } else if (status > 299 && status < 400) { - // nothing to do yet - } else if (status === 409) { - // toast.error('Conflict', 'The resource already exists'); - } else if (status === 404) { - // nothing to do yet - } else if (status >= 500 && status < 600) { - return dispatchError(r); - } else { - // nothing to do yet - } - return r; - }); + return r; + }); }; }