Skip to content

Commit

Permalink
dont show unknown error if the user can retry (#2630)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjosttveit authored Oct 24, 2024
1 parent 3b8636d commit 399708e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/features/instance/ProcessNavigationContext.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useCallback, useState } from 'react';
import { toast } from 'react-toastify';

import { useMutation } from '@tanstack/react-query';

Expand All @@ -9,13 +10,16 @@ import { useApplicationMetadata } from 'src/features/applicationMetadata/Applica
import { useHasPendingAttachments } from 'src/features/attachments/hooks';
import { useLaxInstanceId, useStrictInstanceRefetch } from 'src/features/instance/InstanceContext';
import { useReFetchProcessData } from 'src/features/instance/ProcessContext';
import { Lang } from 'src/features/language/Lang';
import { useCurrentLanguage } from 'src/features/language/LanguageProvider';
import { useNavigationParam } from 'src/features/routing/AppRoutingContext';
import { useUpdateInitialValidations } from 'src/features/validation/backendValidation/backendValidationQuery';
import { appSupportsIncrementalValidationFeatures } from 'src/features/validation/backendValidation/backendValidationUtils';
import { useOnFormSubmitValidation } from 'src/features/validation/callbacks/onFormSubmitValidation';
import { Validation } from 'src/features/validation/validationContext';
import { useNavigatePage } from 'src/hooks/useNavigatePage';
import { isAtLeastVersion } from 'src/utils/versionCompare';
import type { ApplicationMetadata } from 'src/features/applicationMetadata/types';
import type { BackendValidationIssue } from 'src/features/validation';
import type { IActionType, IProcess } from 'src/types/shared';
import type { HttpClientError } from 'src/utils/network/sharedNetworking';
Expand All @@ -38,7 +42,7 @@ function useProcessNext() {
const updateInitialValidations = useUpdateInitialValidations();
const setShowAllBackendErrors = Validation.useSetShowAllBackendErrors();
const onSubmitFormValidation = useOnFormSubmitValidation();
const hasIncrementalValidationFeatures = appSupportsIncrementalValidationFeatures(useApplicationMetadata());
const applicationMetadata = useApplicationMetadata();

const utils = useMutation({
mutationFn: async ({ action }: ProcessNextProps = {}) => {
Expand All @@ -48,9 +52,17 @@ function useProcessNext() {
return doProcessNext(instanceId, language, action)
.then((process) => [process as IProcess, null] as const)
.catch((error) => {
// If process next failed due to validation, return validationIssues instead of throwing
if (error.response?.status === 409 && error.response?.data?.['validationIssues']?.length) {
// If process next failed due to validation, return validationIssues instead of throwing
return [null, error.response.data['validationIssues'] as BackendValidationIssue[]] as const;
} else if (
error.response?.status === 500 &&
error.response?.data?.['detail'] === 'Pdf generation failed' &&
appUnlocksOnPDFFailure(applicationMetadata)
) {
// If process next fails due to the PDF generator failing, don't show unknown error if the app unlocks data elements
toast(<Lang id='process_error.submit_error_please_retry' />, { type: 'error', autoClose: false });
return [null, null];
} else {
throw error;
}
Expand All @@ -63,7 +75,7 @@ function useProcessNext() {
navigateToTask(processData?.currentTask?.elementId);
} else if (validationIssues) {
// Set initial validation to validation issues from process/next and make all errors visible
updateInitialValidations(validationIssues, !hasIncrementalValidationFeatures);
updateInitialValidations(validationIssues, !appSupportsIncrementalValidationFeatures(applicationMetadata));
if (!(await onSubmitFormValidation(true))) {
setShowAllBackendErrors !== ContextNotProvided && setShowAllBackendErrors();
}
Expand Down Expand Up @@ -103,6 +115,10 @@ function useProcessNext() {
return { perform, error: utils.error };
}

function appUnlocksOnPDFFailure({ altinnNugetVersion }: ApplicationMetadata) {
return !altinnNugetVersion || isAtLeastVersion({ actualVersion: altinnNugetVersion, minimumVersion: '8.1.0.115' });
}

interface ContextData {
busy: boolean;
busyWithId: string;
Expand Down
3 changes: 3 additions & 0 deletions src/language/texts/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,5 +411,8 @@ export function en() {
likert: {
left_column_default_header_text: 'Question',
},
process_error: {
submit_error_please_retry: 'Something went wrong when submitting, please try again in a few minutes.',
},
} satisfies NestedTexts;
}
3 changes: 3 additions & 0 deletions src/language/texts/nb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,5 +412,8 @@ export function nb(): FixedLanguageList {
likert: {
left_column_default_header_text: 'Spørsmål',
},
process_error: {
submit_error_please_retry: 'Noe gikk galt under innsendingen, prøv igjen om noen minutter.',
},
} satisfies NestedTexts;
}
3 changes: 3 additions & 0 deletions src/language/texts/nn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,5 +412,8 @@ export function nn(): FixedLanguageList {
likert: {
left_column_default_header_text: 'Spørsmål',
},
process_error: {
submit_error_please_retry: 'Noko gjekk gale med innsending, prøv igjen om nokre minutt.',
},
} satisfies NestedTexts;
}

0 comments on commit 399708e

Please sign in to comment.