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

Create a generic error handling mechanism #10865

Merged
merged 9 commits into from
Aug 29, 2023
Merged

Conversation

mlqn
Copy link
Contributor

@mlqn mlqn commented Aug 22, 2023

Description

  • Created a generic error handling mechanism using :

    axios interceptors seem like the best place for handling errors as they are closer to the HTTP Layer, but using them with react-query can be problematic due to the retry mechanism, which would show an error from the first request and log multiple identical requests. The main drawback of not using axios interceptors is that our error handling won't work if we use axios directly (e.g. XSDUpload).

  • Moved the QueryClient instance inside the component to access the i18n instance, as suggested here.

  • Added a new clientConfig property to pass a QueryClientConfig to ServicesContext, instead of passing a QueryClient instance, as QueryCache and MutationCache can't be set after a QueryClient instance has been created.

Disabling global error message

Now, whenever an API call fails, a toast will be shown displaying a generic error message. This can be problematic if we already have a specific error message, as both error messages will be visible.

Screenshot 2023-08-24 at 11 41 55

To prevent these duplicate error messages, we can disable the global error message by setting meta.hideDefaultError to true (as suggested here and here).

We can also disable it for specific HTTP codes:

return useMutation({
  mutationFn: ...,
  meta: {
    hideDefaultError: (error: AxiosError) => error?.response?.status === 409,
  },
});

Related Issue(s)

Verification

Documentation

  • User documentation is updated with a separate linked PR in altinn-studio-docs. (if applicable)

@github-actions github-actions bot added the solution/studio/designer Issues related to the Altinn Studio Designer solution. label Aug 22, 2023
@mlqn mlqn force-pushed the 10735-generic-error-handling branch from 775149f to 2ba1675 Compare August 23, 2023 10:08
@github-actions github-actions bot added the area/ui-editor Area: Related to the designer tool for assembling app UI in Altinn Studio. label Aug 23, 2023
@codecov
Copy link

codecov bot commented Aug 23, 2023

Codecov Report

Patch coverage: 90.62% and project coverage change: +0.03% 🎉

Comparison is base (6fbadf6) 79.25% compared to head (4cb0a2e) 79.28%.
Report is 28 commits behind head on master.

❗ Current head 4cb0a2e differs from pull request most recent head 8d485c3. Consider uploading reports for the commit 8d485c3 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10865      +/-   ##
==========================================
+ Coverage   79.25%   79.28%   +0.03%     
==========================================
  Files         549      550       +1     
  Lines        9297     9325      +28     
  Branches     1218     1220       +2     
==========================================
+ Hits         7368     7393      +25     
- Misses       1720     1722       +2     
- Partials      209      210       +1     
Files Changed Coverage Δ
...d/packages/shared/src/contexts/ServicesContext.tsx 82.14% <85.00%> (-1.20%) ⬇️
...es/shared/src/components/ErrorBoundaryFallback.tsx 100.00% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions github-actions bot added the area/dashboard Area: Related to the dashboard label Aug 24, 2023
@mlqn mlqn marked this pull request as ready for review August 24, 2023 10:33
Copy link
Contributor

@TomasEng TomasEng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ryddig og bra!

@framitdavid
Copy link
Collaborator

framitdavid commented Aug 25, 2023

Agree with @TomasEng clean and nice work! Loved the way we can pass a configuration object for QueryClient into the ServiceContext. 👏 Looking forward to getting this merged into the master branch. :)

Copy link
Contributor

@TomasEng TomasEng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

@mlqn mlqn merged commit 8220c9e into master Aug 29, 2023
6 checks passed
@mlqn mlqn deleted the 10735-generic-error-handling branch August 29, 2023 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/dashboard Area: Related to the dashboard area/ui-editor Area: Related to the designer tool for assembling app UI in Altinn Studio. solution/studio/designer Issues related to the Altinn Studio Designer solution.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants