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

Modernisering feilmeldingskode #6482

Merged
merged 21 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c12e598
Ny komponent for stor feilmelding på side.
josstn Aug 14, 2024
c953f89
Skriver om ForbiddenPage komponent til å bruke ny BigError komponent.
josstn Aug 14, 2024
1391eea
Skriver om NotFoundPage komponent til å bruke ny BigError komponent.
josstn Aug 14, 2024
88373b6
Skriver om UnauthorizedPage komponent til å bruke ny BigError komponent.
josstn Aug 15, 2024
f1b25f0
Skriver om IngenBehandlingValgtPanel komponent til å ikkje bruke intl…
josstn Aug 15, 2024
e2f527c
Fjerna ubrukt textCode prop på ErrorBoundary, lagt til storybook test
josstn Aug 15, 2024
0e5f727
Endra ErrorPage til å bruke BigError, fjerna ErrorPageWrapper.
josstn Aug 15, 2024
742eb71
Legg til standardfeilmelding og større margin på BigError.
josstn Aug 15, 2024
7b8cf8c
Justert feilmelding som viser når ErrorBoundary blir utløst.
josstn Aug 15, 2024
d634a9b
ErrorBoundary viser no referanse til sentry rapport.
josstn Aug 15, 2024
9ea8ca6
Flytta sak-infosider til v2/gui/src/sak/feilmeldinger. Sletta gammal …
josstn Aug 15, 2024
16826a8
Fiks så CopyButton på ErrorPage blir inline i feilmelding.
josstn Aug 15, 2024
7aa5091
typofix i BigError.tsx
josstn Aug 15, 2024
7354429
NetworkErrorPage komponent for bruk ved nettverksfeil lagt til.
josstn Aug 15, 2024
d4e41a4
Handter nettverksfeil i BehandlingTilbakekrevingIndex.
josstn Aug 15, 2024
b0851cb
Fjern utdatert referanse til sak-infosider, fiks ulovlig import path.
josstn Aug 16, 2024
b788582
css module typegen
josstn Aug 16, 2024
b0d6b30
legg til "--allow-empty" på lint-staged hook.
josstn Aug 16, 2024
3f17890
Behold quotes i modules.d.css.ts filer
josstn Aug 16, 2024
aefce92
Revert "legg til "--allow-empty" på lint-staged hook."
josstn Aug 16, 2024
6be3b51
Merge branch 'master' into errorhandling-dataload
josstn Aug 19, 2024
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
@@ -1,17 +1,19 @@
import React, { useEffect, useState, useCallback } from 'react';
import React, { useCallback, useEffect, useState } from 'react';

import { ReduxFormStateCleaner, Rettigheter, useSetBehandlingVedEndring } from '@k9-sak-web/behandling-felles';
import { KodeverkMedNavn, Behandling, Fagsak, FagsakPerson } from '@k9-sak-web/types';
import { Behandling, Fagsak, FagsakPerson, KodeverkMedNavn } from '@k9-sak-web/types';
import { LoadingPanel } from '@fpsak-frontend/shared-components';
import { RestApiState, useRestApiErrorDispatcher } from '@k9-sak-web/rest-api-hooks';

import TilbakekrevingPaneler from './components/TilbakekrevingPaneler';
import FetchedData from './types/fetchedDataTsType';
import {
restApiTilbakekrevingHooks,
requestTilbakekrevingApi,
restApiTilbakekrevingHooks,
TilbakekrevingBehandlingApiKeys,
} from './data/tilbakekrevingBehandlingApi';
import NetworkErrorPage from '@k9-sak-web/gui/sak/feilmeldinger/NetworkErrorPage.js';
import { extractErrorInfo } from '../../rest-api-hooks/src/error/extractErrorInfo.js';

const tilbakekrevingData = [
{ key: TilbakekrevingBehandlingApiKeys.AKSJONSPUNKTER },
Expand Down Expand Up @@ -124,7 +126,7 @@ const BehandlingTilbakekrevingIndex = ({
};
}, []);

const { data, state } = restApiTilbakekrevingHooks.useMultipleRestApi<FetchedData>(tilbakekrevingData, {
const { data, state, error } = restApiTilbakekrevingHooks.useMultipleRestApi<FetchedData>(tilbakekrevingData, {
keepData: true,
updateTriggers: [behandling?.versjon],
suspendRequest: !behandling,
Expand All @@ -135,6 +137,10 @@ const BehandlingTilbakekrevingIndex = ({
return <LoadingPanel />;
}

if (state === RestApiState.ERROR) {
return <NetworkErrorPage {...extractErrorInfo(error)} />;
}

return (
<>
<ReduxFormStateCleaner
Expand Down
28 changes: 28 additions & 0 deletions packages/rest-api-hooks/src/error/extractErrorInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { AxiosError } from 'axios';

interface ErrorInfo {
navCallId: string | undefined;
statusCode: number | undefined;
}

/**
* Kan brukast for å hente ut meta informasjon frå AxiosError som har skjedd.
* Brukast for å vise referanse i feilmelding til bruker, slik at denne kan inkluderast i evt feilmelding vidare.
*
* @param error feil som har oppstått
* @returns objekt med Nav-Callid string og http status kode for respons viss denne info finnast.
*/
export const extractErrorInfo = (error: unknown): Readonly<ErrorInfo> => {
const resp: ErrorInfo = {
navCallId: undefined,
statusCode: undefined,
};
if (error instanceof AxiosError) {
const callId = error.config.headers.get('Nav-Callid');
if (typeof callId === 'string') {
resp.navCallId = callId;
}
resp.statusCode = error.status;
}
return resp;
};
1 change: 0 additions & 1 deletion packages/sak-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"@k9-sak-web/rest-api-hooks": "1.0.0",
"@k9-sak-web/sak-aktor": "1.0.0",
"@k9-sak-web/sak-behandling-velger": "1.0.0",
"@k9-sak-web/sak-infosider": "1.0.0",
"@k9-sak-web/sak-meldinger": "1.0.0",
"@k9-sak-web/sak-meny-marker-behandling": "1.0.0",
"@k9-sak-web/sak-notat": "1.0.0",
Expand Down
3 changes: 2 additions & 1 deletion packages/sak-app/src/app/AppIndex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { useLocation } from 'react-router-dom';
import { parseQueryString } from '@fpsak-frontend/utils';
import { useRestApiError, useRestApiErrorDispatcher } from '@k9-sak-web/rest-api-hooks';
import EventType from '@k9-sak-web/rest-api/src/requestApi/eventType';
import { ForbiddenPage, UnauthorizedPage } from '@k9-sak-web/sak-infosider';
import ForbiddenPage from '@k9-sak-web/gui/sak/feilmeldinger/ForbiddenPage.js';
import UnauthorizedPage from '@k9-sak-web/gui/sak/feilmeldinger/UnauthorizedPage.js';
import { NavAnsatt } from '@k9-sak-web/types';

import { K9sakApiKeys, restApiHooks } from '../data/k9sakApi';
Expand Down
45 changes: 45 additions & 0 deletions packages/sak-app/src/app/ErrorBoundary.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import ErrorBoundary from './ErrorBoundary.js';
import { Meta, StoryObj } from '@storybook/react';
import { fn, expect } from '@storybook/test';
import { useEffect } from 'react';

const meta = {
title: 'sak/sak-app',
component: ErrorBoundary,
} satisfies Meta<typeof ErrorBoundary>;

export default meta;

type Story = StoryObj<typeof meta>;

const NonFailingChild = () => <p>Nothing to see here, move along.</p>;

const FailingChild = () => {
useEffect(() => {
throw new Error('TEST FAIL');
}, []);
return <p>Error boundary should be displayed instead of this</p>;
};

export const ErrorBoundaryNotTriggered: Story = {
args: {
errorMessageCallback: fn(),
children: <NonFailingChild />,
},
play: async ({ args }) => {
await expect(args.errorMessageCallback).toHaveBeenCalledTimes(0);
},
};

export const ErrorBoundaryTriggered: Story = {
args: {
errorMessageCallback: fn(),
children: <FailingChild />,
},
play: async ({ canvas, args }) => {
await expect(args.errorMessageCallback).toHaveBeenCalledOnce();
await expect(canvas.getByRole('heading')).toHaveTextContent(
'Det har oppstått en teknisk feil i denne behandlingen.',
);
},
};
19 changes: 11 additions & 8 deletions packages/sak-app/src/app/ErrorBoundary.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
import React, { Component, ReactNode, ErrorInfo } from 'react';
import { captureException, withScope } from '@sentry/browser';

import { ErrorPage } from '@k9-sak-web/sak-infosider';
import ErrorPage from '@k9-sak-web/gui/sak/feilmeldinger/ErrorPage.js';

interface OwnProps {
errorMessageCallback: (error: any) => void;
textCode?: string;
children: ReactNode;
doNotShowErrorPage?: boolean;
}

interface State {
hasError: boolean;
sentryId: string | undefined;
}

export class ErrorBoundary extends Component<OwnProps, State> {
Expand All @@ -21,7 +20,7 @@ export class ErrorBoundary extends Component<OwnProps, State> {

constructor(props: OwnProps) {
super(props);
this.state = { hasError: false };
this.state = { hasError: false, sentryId: undefined };
}

static getDerivedStateFromError() {
Expand All @@ -35,7 +34,11 @@ export class ErrorBoundary extends Component<OwnProps, State> {
withScope(scope => {
Object.keys(info).forEach(key => {
scope.setExtra(key, info[key]);
captureException(error);
const sentryId = captureException(error);
this.setState({
...this.state,
sentryId,
});
});
});

Expand All @@ -54,10 +57,10 @@ export class ErrorBoundary extends Component<OwnProps, State> {
}

render(): ReactNode {
const { children, doNotShowErrorPage, textCode } = this.props;
const { hasError } = this.state;
const { children, doNotShowErrorPage } = this.props;
const { hasError, sentryId } = this.state;

return hasError && !doNotShowErrorPage ? <ErrorPage textCode={textCode} /> : children;
return hasError && !doNotShowErrorPage ? <ErrorPage sentryId={sentryId} /> : children;
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/sak-app/src/app/components/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import React from 'react';
import { Route, Routes } from 'react-router-dom';

import { NotFoundPage } from '@k9-sak-web/sak-infosider';
import NotFoundPage from '@k9-sak-web/gui/sak/feilmeldinger/NotFoundPage.js';

import AktoerIndex from '../../aktoer/AktoerIndex';
import FagsakIndex from '../../fagsak/FagsakIndex';
Expand Down
6 changes: 3 additions & 3 deletions packages/sak-app/src/behandling/BehandlingerIndex.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { Route, Routes } from 'react-router-dom';

import { BehandlingAppKontekst, Fagsak, ArbeidsgiverOpplysningerWrapper } from '@k9-sak-web/types';
import { IngenBehandlingValgtPanel } from '@k9-sak-web/sak-infosider';
import IngenBehandlingValgtPanel from '@k9-sak-web/gui/sak/feilmeldinger/IngenBehandlingValgtPanel.js';

import BehandlingIndex from './BehandlingIndex';
import { behandlingRoutePath } from '../app/paths';
Expand All @@ -25,15 +25,15 @@ export const BehandlingerIndex = ({
<Routes>
<Route
path={behandlingRoutePath}
element={(
element={
<BehandlingIndex
fagsak={fagsak}
alleBehandlinger={alleBehandlinger}
arbeidsgiverOpplysninger={arbeidsgiverOpplysninger}
setBehandlingIdOgVersjon={setBehandlingIdOgVersjon}
setRequestPendingMessage={setRequestPendingMessage}
/>
)}
}
/>
<Route path="/" element={<IngenBehandlingValgtPanel numBehandlinger={alleBehandlinger.length} />} />
</Routes>
Expand Down
13 changes: 0 additions & 13 deletions packages/sak-infosider/i18n/nb_NO.json

This file was deleted.

5 changes: 0 additions & 5 deletions packages/sak-infosider/index.ts

This file was deleted.

12 changes: 0 additions & 12 deletions packages/sak-infosider/package.json

This file was deleted.

24 changes: 0 additions & 24 deletions packages/sak-infosider/src/ErrorPage.spec.tsx

This file was deleted.

11 changes: 0 additions & 11 deletions packages/sak-infosider/src/ErrorPage.tsx

This file was deleted.

21 changes: 0 additions & 21 deletions packages/sak-infosider/src/ForbiddenPage.spec.tsx

This file was deleted.

24 changes: 0 additions & 24 deletions packages/sak-infosider/src/ForbiddenPage.tsx

This file was deleted.

19 changes: 0 additions & 19 deletions packages/sak-infosider/src/InfosiderSakIndex.stories.tsx

This file was deleted.

29 changes: 0 additions & 29 deletions packages/sak-infosider/src/IngenBehandlingValgtPanel.spec.tsx

This file was deleted.

Loading