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

[Data-Studio] Handle network error #306

Merged
merged 1 commit into from
Aug 24, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ function ApolloHandler({children}: IApolloHandlerProps): JSX.Element {
}

if (networkError) {
// Check if error response is JSON
try {
JSON.parse(networkError.message);
} catch (e) {
// If not replace parsing error message with real one
networkError.message = t('error.network_error_occured_details');
}

const errorContent = t('error.network_error_occurred');

const info: IInfo = {
Expand Down
1 change: 1 addition & 0 deletions apps/data-studio/src/locales/en/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@
"access_denied_details": "You are not allowed to access this element, please contact an administrator",
"graphql_error_occurred": "An error ocurred: {{error}}",
"network_error_occurred": "An network error occurred",
"network_error_occured_details": "Unable to connect to server. Please check your Internet connection.",
"PERMISSION_ERROR": "You are not allowed to perform this action",
"INTERNAL_ERROR": "An internal error occurred",
"page_not_found": "Page not found"
Expand Down
1 change: 1 addition & 0 deletions apps/data-studio/src/locales/fr/translations.json
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@
"access_denied_details": "Vous n'êtes pas autorisé à accéder à cet élément, veuillez contacter un administrateur.",
"graphql_error_occurred": "Une erreur est survenue: {{error}}",
"network_error_occurred": "Une erreur de connexion est survenue",
"network_error_occured_details": "Impossible de se connecter au serveur. Veuillez vérifier votre connexion Internet.",
"PERMISSION_ERROR": "Vous n'êtes pas autorisé à effectuer cette action",
"INTERNAL_ERROR": "Une erreur interne est survenue",
"page_not_found": "La page demandée n'existe pas"
Expand Down
4 changes: 2 additions & 2 deletions libs/ui/src/components/ErrorDisplay/ErrorDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function ErrorDisplay({
showActionButton = true,
type = ErrorDisplayTypes.ERROR
}: IErrorProps): JSX.Element {
const {t} = useTranslation();
const {t, i18n} = useTranslation();
const history = useHistory();

const _handleBackHomeClick = () => history.replace('/');
Expand All @@ -39,7 +39,7 @@ function ErrorDisplay({

const errorByType = {
[ErrorDisplayTypes.ERROR]: {
title: t('error.error_occurred'),
title: i18n.isInitialized ? t('error.error_occurred') : 'An error occurred',
icon: <CloseCircleFilled color="red" />,
message: '',
actionButton: null
Expand Down
13 changes: 12 additions & 1 deletion libs/ui/src/hooks/useAppLang/useAppLang.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,21 @@ export default function useAppLang() {
const _fetchLang = async () => {
try {
const res = await fetch('/global-lang', {method: 'GET'});

// make the promise be rejected if we didn't get a 2xx response
if (!res.ok) {
throw new Error(
res.status === 404
? 'Unable to connect to server. Please check your Internet connection.'
: res.statusText,
{cause: res}
);
}

const resContent = await res.text();
setLang(resContent);
} catch (err) {
setError(String(err));
setError(err.message);
} finally {
setIsLoading(false);
}
Expand Down
Loading