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

fix(http)!: throw correct error in jsonSelector #2196

Merged
merged 1 commit into from
May 24, 2024

Conversation

odinr
Copy link
Collaborator

@odinr odinr commented May 23, 2024

Why

This pull request introduces a fix to the jsonSelector function in the @equinor/fusion-framework-module-http package.

The current behavior is that the jsonSelector function was not properly checking the error type in the catch block. This led to always throwing a parser error, even when the correct error was in the cause property of the HttpJsonResponseError.

The new behavior is that the jsonSelector function now correctly checks if the error is an instance of HttpJsonResponseError, and then properly handles the error data and cause. This ensures that developers who have caught the error and assumed the cause property would give the proper error data, will now receive the correct information.

This change might introduce breaking changes:
If for some reason developers has catched the error and assumed the cause property would give the proper error data, this will no longer be the case.

try {
  await jsonSelector(response);
} catch (error) {
  if(error instanceof HttpJsonResponseError) {
-    const data = error.cause instanceof HttpJsonResponseError ? err.cause.data : null;
+    const data = error instanceof HttpJsonResponseError ? error.data : null;
    if(data) {
      console.error('the request was not `ok`, see provided error data', data);
    } else {
      console.error('failed to parse data from response, see provided cause', error.cause);
    }
  }
}

Check off the following:

  • Confirm that I checked changes to branch which I am merging into.
    • I have validated included files
    • My code does not generate new linting warnings
    • My PR is not a duplicate, check existing pr`s
  • Confirm that the I have completed the self-review checklist.
  • Confirm that my changes meet our code of conduct.

@odinr odinr self-assigned this May 23, 2024
Copy link

changeset-bot bot commented May 23, 2024

🦋 Changeset detected

Latest commit: 347a823

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 21 packages
Name Type
@equinor/fusion-framework-module-http Patch
@equinor/fusion-framework-app Patch
@equinor/fusion-framework-cli Patch
@equinor/fusion-framework Patch
@equinor/fusion-framework-module-service-discovery Patch
@equinor/fusion-framework-module-widget Patch
@equinor/fusion-framework-legacy-interopt Patch
@equinor/fusion-framework-react-module-http Patch
@equinor/fusion-framework-widget Patch
@equinor/fusion-framework-cookbook-app-react-feature-flag Patch
@equinor/fusion-framework-react-app Patch
@equinor/fusion-framework-cookbook-app-react-context-custom-error Patch
@equinor/fusion-framework-cookbook-app-react-context Patch
@equinor/fusion-framework-react Patch
@equinor/fusion-framework-react-widget Patch
@equinor/fusion-framework-react-components-bookmark Patch
@equinor/fusion-framework-react-components-people-provider Patch
@equinor/fusion-framework-react-module-bookmark Patch
@equinor/fusion-framework-module-signalr Patch
@equinor/fusion-framework-react-module-signalr Patch
@equinor/fusion-framework-react-module-context Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added 🐞 bug Something isn't working 🧬 Modules labels May 23, 2024
@odinr odinr force-pushed the fix/module-http/json-selector/slipped-catch branch from e3d1970 to 85e42b3 Compare May 23, 2024 23:41
@odinr odinr force-pushed the fix/module-http/json-selector/slipped-catch branch from 85e42b3 to 4856b47 Compare May 23, 2024 23:43
The `jsonSelector` function is not checking the error type in the `catch`
block. This led to always throwing a parser error, even when the actual
error was due to an unsuccessful response.

BREAKING CHANGE:
If for some reason developers has catched the error and assumed the cause property would give the proper error data, this will no longer be the case.
@odinr odinr force-pushed the fix/module-http/json-selector/slipped-catch branch from 4856b47 to 347a823 Compare May 24, 2024 09:00
@odinr odinr marked this pull request as ready for review May 24, 2024 09:03
@odinr odinr requested a review from a team as a code owner May 24, 2024 09:03
Copy link
Contributor

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 12.74% 3682 / 28882
🔵 Statements 12.74% 3682 / 28882
🔵 Functions 12.67% 92 / 726
🔵 Branches 27.27% 225 / 825
File Coverage
File Stmts % Branch % Funcs % Lines Uncovered Lines
Changed Files
packages/modules/http/src/lib/selectors/json-selector.ts 39.58% 100% 0% 39.58% 18-46
Generated in workflow #6322

@odinr odinr merged commit 1e60919 into main May 24, 2024
14 checks passed
@odinr odinr deleted the fix/module-http/json-selector/slipped-catch branch May 24, 2024 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants