Skip to content

Commit

Permalink
feat: add error text on lacking text
Browse files Browse the repository at this point in the history
  • Loading branch information
magsyg committed Dec 9, 2024
1 parent c5a9ca8 commit 745dc98
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions frontend/src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type { TextItemValue } from './constants/TextItems';
import { useAuthContext } from './context/AuthContext';
import { useGlobalContext } from './context/GlobalContextProvider';
import type { TextItemDto } from './dto';
import { STATUS } from './http_status_codes';
import { LANGUAGES } from './i18n/types';

// Make typescript happy.
Expand Down Expand Up @@ -75,9 +76,19 @@ export function useTextItem(key: TextItemValue, language?: string): string | und
const { i18n } = useTranslation();
const isNorwegian = (language || i18n.language) === LANGUAGES.NB;
useEffect(() => {
getTextItem(key).then((data) => {
setTextItem(data);
});
getTextItem(key)
.then((data) => {
setTextItem(data);
})
.catch((error) => {
if (error.request.status === STATUS.HTTP_404_NOT_FOUND) {
}
setTextItem({
key: 'HEST',
text_nb: 'ERROR ERROR kontakt MG:WEB om manglende tekst ERROR ERROR',
text_en: 'ERROR ERROR contact MG:WEB about lacking text ERROR ERROR',
});
});
}, [key]);
return isNorwegian ? textItem?.text_nb : textItem?.text_en;
}
Expand Down

0 comments on commit 745dc98

Please sign in to comment.