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

chore(TransactionFeedV2): Add error handling to Transaction Feed V2 #6151

Merged
merged 4 commits into from
Oct 16, 2024

Conversation

sviderock
Copy link
Contributor

Description

5th PR for RET-1207. Adds error handling middleware as per the docs and also copies the same logic of error handling from queryHelper.

Test plan

Eveything works as before.

Related issues

Backwards compatibility

Yes

Network scalability

If a new NetworkId and/or Network are added in the future, the changes in this PR will:

  • Continue to work without code changes, OR trigger a compilation error (guaranteeing we find it when a new network is added)

Copy link

codecov bot commented Oct 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.77%. Comparing base (76f1605) to head (601dbb1).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##             main    #6151    +/-   ##
========================================
  Coverage   88.76%   88.77%            
========================================
  Files         727      727            
  Lines       30776    30786    +10     
  Branches     5627     5631     +4     
========================================
+ Hits        27319    27330    +11     
- Misses       3259     3414   +155     
+ Partials      198       42   -156     
Files with missing lines Coverage Δ
src/redux/apiReducersList.ts 100.00% <100.00%> (ø)
src/transactions/feed/TransactionFeedV2.tsx 90.00% <100.00%> (+0.63%) ⬆️

... and 68 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 76f1605...601dbb1. Read the comment docs.

@@ -7,3 +7,5 @@ export const apiReducersList = {
} as const

export const apiMiddlewares = [transactionFeedV2Api.middleware]

export const apiReducersKeys = Object.keys(apiReducersList)
Copy link
Member

Choose a reason for hiding this comment

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

nit: Do we need this in more than one location? I couldn't quite see it from this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jeanregisser Not really, just thought it might be a little more convenient to have api-related stuff exported from this file but I am totally fine with both approaches. I'll revert this one.

Copy link
Member

@jeanregisser jeanregisser Oct 14, 2024

Choose a reason for hiding this comment

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

We can keep it I guess, I was just wondering why it needed to change now in this PR.

Copy link
Contributor Author

@sviderock sviderock Oct 14, 2024

Choose a reason for hiding this comment

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

@jeanregisser initially I was also using apiReducersKeys in the error logger to provide more precise info on what specific endpoint caused the error, but as I've figured that I can just pass the whole arg - I removed the usage but kept apiReducersKeys at the new place.

src/redux/api.ts Outdated
Comment on lines 16 to 29
export const rtkQueryErrorLoggerMiddleware: Middleware =
(api: MiddlewareAPI) => (next) => (action) => {
if (isRejectedWithValue(action)) {
const errorMessage =
'data' in action.error
? (action.error.data as { message: string }).message
: action.error.message

Logger.error('RTK-Query', errorMessage || 'An error occured', action)
api.dispatch(showError(ErrorMessages.FETCH_FAILED) as Action)
}

return next(action)
}
Copy link
Member

@jeanregisser jeanregisser Oct 14, 2024

Choose a reason for hiding this comment

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

Ah, we don't really want this generic error message anymore at this level.
Could we move it to be at the component level instead?

We now usually prefer showing inline errors, instead of the red banner at the top.
To avoid showing them from background tasks we have in the app, which could show up at inappropriate times (e.g. the user navigated to another screen, so the red banner is not directly relevant for something that's in the TX feed).

FETCH_FAILED is really just used for the TX feed. And we should probably rename it.
I know moving it to the component won't change the fact that it could still trigger at inappropriate times.
But at least we can update the behavior later from the component.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jeanregisser Gotcha, I will adjust this to the new desirable approach.
It seems like queryHelper only uses red banner for error. Could you please point me at the example with the inline error?

Copy link
Member

@jeanregisser jeanregisser Oct 14, 2024

Choose a reason for hiding this comment

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

What I meant is to control the error behavior from the component.
i.e. dispatch from the component instead of a generic error hander.
We can't yet switch to an inline error as we first need approved designs for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, got it. I'll move it to the component.

@sviderock
Copy link
Contributor Author

@jeanregisser updated

@sviderock sviderock changed the title chore(feed): Add error handling to Transaction Feed V2 chore(TransactionFeedV2): Add error handling to Transaction Feed V2 Oct 15, 2024
@@ -39,6 +42,7 @@ type PaginatedData = {
// Query poll interval
const POLL_INTERVAL_MS = 10000 // 10 sec
const FIRST_PAGE_TIMESTAMP = 0
const LOGGER_TAG = 'transactions/feed/TransactionFeedV2'
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can just call this TAG, since it's only ever used for logging purposes anyways (and matches the naming convention we typically use)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jophish sure! I'll address this in the follow-up PR.

Copy link
Member

Choose a reason for hiding this comment

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

nit: what's the problem with doing it here, since it's this PR that introduces it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jeanregisser no problem with doing it here. I thought this should be a small enough change that it can be addressed within the next PR that I was already working on so there's less potential back-and-forth with rebasing all the follow-up PRs. But you're right, it makes sense to make the change here if this change is purely related to this PRs goal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jeanregisser updated

Copy link
Member

@jeanregisser jeanregisser left a comment

Choose a reason for hiding this comment

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

🚀

@@ -39,6 +42,7 @@ type PaginatedData = {
// Query poll interval
const POLL_INTERVAL_MS = 10000 // 10 sec
const FIRST_PAGE_TIMESTAMP = 0
const LOGGER_TAG = 'transactions/feed/TransactionFeedV2'
Copy link
Member

Choose a reason for hiding this comment

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

nit: what's the problem with doing it here, since it's this PR that introduces it?

@sviderock sviderock added this pull request to the merge queue Oct 16, 2024
Merged via the queue into main with commit 6a8884a Oct 16, 2024
15 checks passed
@sviderock sviderock deleted the slava/feed-v2-error-handling branch October 16, 2024 14:45
bakoushin pushed a commit that referenced this pull request Oct 17, 2024
…6151)

### Description
5th PR for RET-1207. Adds error handling middleware as per [the
docs](https://redux-toolkit.js.org/rtk-query/usage/error-handling) and
also copies the same logic of error handling from
[queryHelper](https://github.com/valora-inc/wallet/blob/main/src/transactions/feed/queryHelper.ts).

### Test plan
Eveything works as before.

### Related issues

- Relates to RET-1207

### Backwards compatibility
Yes

### Network scalability

If a new NetworkId and/or Network are added in the future, the changes
in this PR will:

- [x] Continue to work without code changes, OR trigger a compilation
error (guaranteeing we find it when a new network is added)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants