Skip to content

Commit

Permalink
ES - tester feilmelding ved feil ved innsending
Browse files Browse the repository at this point in the history
  • Loading branch information
grutkowska committed Aug 10, 2023
1 parent e93e381 commit c536dff
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 5 deletions.
24 changes: 20 additions & 4 deletions apps/engangsstonad/src/app/steps/oppsummering/Oppsummering.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { bemUtils, Block, intlUtils, Locale, Step, StepButtonWrapper } from '@navikt/fp-common';
import { Button, GuidePanel } from '@navikt/ds-react';
import { useState } from 'react';
import { useEffect, useState } from 'react';
import { FormattedMessage, useIntl } from 'react-intl';
import Oppsummeringspunkt from './Oppsummeringspunkt';
import Person from 'app/types/domain/Person';
Expand All @@ -13,15 +13,20 @@ import { OppsummeringFormComponents, initialOppsummeringValues, OppsummeringForm
import { UnansweredQuestionsInfo } from '@navikt/sif-common-formik-ds/lib';
import oppsummeringQuestionsConfig from './oppsummeringQuestionsConfig';
import { EngangsstønadSøknadDto } from 'app/types/domain/EngangsstønadSøknad';
import { mapStateForInnsending } from 'app/util/apiUtils';
import {
FEIL_VED_INNSENDING,
getErrorCallId,
mapStateForInnsending,
sendErrorMessageToSentry,
UKJENT_UUID,
} from 'app/util/apiUtils';
import Api from 'app/api/api';
import { useNavigate, Link } from 'react-router-dom';
import actionCreator from 'app/context/action/actionCreator';
import { onAvbrytSøknad } from 'app/util/globalUtil';
import { logAmplitudeEvent } from 'app/amplitude/amplitude';
import { PageKeys } from 'app/types/PageKeys';
import OmDegOppsummering from './OmDegOppsummering';

import './oppsummering.less';

interface Props {
Expand All @@ -35,6 +40,7 @@ const Oppsummering: React.FunctionComponent<Props> = ({ person, locale }) => {
const { state, dispatch } = useEngangsstønadContext();
const navigate = useNavigate();
const [isSending, setIsSending] = useState(false);
const [submitError, setSubmitError] = useState<any>(undefined);

logAmplitudeEvent('sidevisning', {
app: 'engangsstonadny',
Expand All @@ -60,10 +66,20 @@ const Oppsummering: React.FunctionComponent<Props> = ({ person, locale }) => {
team: 'foreldrepenger',
});
} catch (error) {
navigate('/kvittering');
setSubmitError(error);
}
};

useEffect(() => {
if (submitError !== undefined) {
sendErrorMessageToSentry(submitError);
const submitErrorCallId = getErrorCallId(submitError);
const callIdForBruker =
submitErrorCallId !== UKJENT_UUID ? submitErrorCallId.slice(0, 8) : submitErrorCallId;
throw new Error(FEIL_VED_INNSENDING + callIdForBruker);
}
}, [submitError]);

return (
<OppsummeringFormComponents.FormikWrapper
initialValues={initialOppsummeringValues}
Expand Down
35 changes: 34 additions & 1 deletion apps/engangsstonad/src/app/util/apiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ import InformasjonOmUtenlandsopphold, { Utenlandsopphold } from 'app/types/domai
import { BostedUtland } from 'app/steps/utenlandsopphold/bostedUtlandListAndDialog/types';
import dayjs from 'dayjs';
import { Locale } from '@navikt/fp-common';

import * as Sentry from '@sentry/browser';
import utc from 'dayjs/plugin/utc';
import Adopsjon from 'app/types/domain/Adopsjon';
import { AxiosError } from 'axios';

dayjs.extend(utc);

export const FEIL_VED_INNSENDING =
'Det har oppstått et problem med innsending av søknaden. Vennligst prøv igjen senere. Hvis problemet vedvarer, kontakt oss og oppgi feil id: ';

export const UKJENT_UUID = 'ukjent uuid';

const isArrayOfAttachments = (attachment: Attachment) => {
return Array.isArray(attachment) && attachment.some((element: Attachment) => element.filename);
};
Expand Down Expand Up @@ -99,3 +105,30 @@ export const mapStateForInnsending = (state: EngangsstønadContextState, locale:
vedlegg: mapAttachments(JSON.parse(JSON.stringify(state.søknad))),
};
};

export const sendErrorMessageToSentry = (error: AxiosError<any>) => {
const errorCallId = getErrorCallId(error) + '. ';
const errorTimestamp = getErrorTimestamp(error) + '. ';
const hideNumbersAndTrim = (tekst: string): string => {
return tekst.replace(/\d/g, '*').slice(0, 250) + '...';
};

let errorString = errorCallId + errorTimestamp;
if (error.request && error.request.data && error.request.data.messages) {
errorString = errorString + hideNumbersAndTrim(error.request.data.messages);
} else if (error.response && error.response.data && error.response.data.messages) {
errorString = errorString + hideNumbersAndTrim(error.response.data.messages);
}
if (error.message) {
errorString = errorString + error.message;
}
Sentry.captureMessage(errorString);
};

export const getErrorCallId = (error: AxiosError<any>): string => {
return error.response && error.response.data && error.response.data.uuid ? error.response.data.uuid : UKJENT_UUID;
};

export const getErrorTimestamp = (error: AxiosError<any>): string => {
return error.response && error.response.data && error.response.data.timestamp ? error.response.data.timestamp : '';
};

0 comments on commit c536dff

Please sign in to comment.