Skip to content

Commit

Permalink
Capture error instead of message
Browse files Browse the repository at this point in the history
  • Loading branch information
tu55eladd committed Dec 23, 2024
1 parent 04f2062 commit 12a4fc7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
10 changes: 9 additions & 1 deletion src/utils/errorCapture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ declare const window: {
captureMessage: (message: string) => void;
};

export const captureException = (exception: any) => {
export const captureException = (exception: Error) => {
if (window.captureException) {
window.captureException(exception);
}
Expand All @@ -16,3 +16,11 @@ export const captureMessage = (message: string) => {
window.captureMessage(message);
}
};

export const captureMaybeError = (errorMessage: string, error: Error | any) => {
if (error instanceof Error) {
captureException(new Error(errorMessage, error));
} else {
captureMessage(errorMessage);
}
};
8 changes: 4 additions & 4 deletions src/view/dialogProvider/dialogStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useShallow } from 'zustand/react/shallow';
import { hentDialogerGraphql } from './dialogGraphql';
import { eqKladd, KladdStore } from '../KladdProvider';
import { UnautorizedError } from '../../utils/fetchErrors';
import { captureMessage } from '../../utils/errorCapture';
import { captureException, captureMaybeError, captureMessage } from '../../utils/errorCapture';

export const initDialogState: DialogState = {
status: Status.INITIAL,
Expand Down Expand Up @@ -61,7 +61,7 @@ export const useDialogStore = create(
return dialoger;
})
.catch((e) => {
captureMessage(`Kunne ikke hente dialogdata ${e.toString()}`);
captureMaybeError(`Kunne ikke hente dialogdata ${e.toString()}`, e);
set(
(prevState) => ({ ...prevState, status: Status.ERROR, error: e }),
false,
Expand Down Expand Up @@ -147,7 +147,7 @@ export const useDialogStore = create(
}
} catch (e) {
if (e instanceof UnautorizedError) {
captureMessage('UnautorizedError 401 på henting av sist oppdatert');
captureMessage('UnauthorizedError 401 på henting av sist oppdatert');
} else {
captureMessage('Kunne ikke hente sist oppdatert');
}
Expand Down Expand Up @@ -207,7 +207,7 @@ export const useDialogStore = create(
return dialog;
})
.catch((err) => {
console.error('Kunne ikke sende melding', err);
captureMaybeError(`Kunne ikke sende melding: ${err.toString()}`, err);
set({ status: Status.ERROR }, false, 'sendMelding/rejected');
return undefined;
});
Expand Down

0 comments on commit 12a4fc7

Please sign in to comment.