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

Handle invalid pagination parameters via exceptions #121

Merged
merged 8 commits into from
Feb 13, 2023

Conversation

csillag
Copy link
Contributor

@csillag csillag commented Feb 10, 2023

This depends on #124. (That's the first commit.) Please merge that one first, then rebase.

This is an alternate implementation of #119. (We only need one of them.)

This time we throw an error from the pagination hook, and apply React Router's errorElement feature to catch it.

Analysis:

  • The benefit is that the happy path and the error path are completely separated.
  • The drawback is that there is no TypeScript-level test to verify that the errorElement (or some other error boundary) is always there.

@csillag csillag force-pushed the csillag/handle-invalid-page-numbers-with-exceptions branch 3 times, most recently from 4fda9d7 to 8c5aafe Compare February 10, 2023 06:43
@csillag csillag force-pushed the csillag/handle-invalid-page-numbers-with-exceptions branch 5 times, most recently from 00e11c0 to 1871cab Compare February 10, 2023 13:20
Comment on lines +9 to +11
// This would be nicer, but this would also trigger react-error-overlay (besides our error boundary).
// We don't want that, so now, we are stuck with throwing a string, instead of a proper error.
// throw new AppError(AppErrors.InvalidPageNumber)
Copy link
Member

Choose a reason for hiding this comment

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

😢

src/app/components/ErrorDisplay/index.tsx Show resolved Hide resolved
Comment on lines 35 to 38
<TransactionsCard blockHeight={blockHeight} />
<ErrorBoundary>
<TransactionsCard blockHeight={blockHeight} />
</ErrorBoundary>
Copy link
Member

Choose a reason for hiding this comment

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

I find this more awkward than a full page error (but it should never happen so it doesn't matter)

Without With
localhost_1234_emerald_blocks_1942688_page=ff localhost_1234_emerald_blocks_1942688_page=ff (1)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I find the first one more awkward. Technically speaking the error only impacts the transaction list, so why shouldn't we seen the data about the block itself?

Copy link
Member

Choose a reason for hiding this comment

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

I see first one as giving clear instructions that URL is malformed. And second one like it could be an app bug

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can see your point. I wonder which viewpoint is more prevalent. I'm inclined to defer this question to @donouwens .

Copy link
Collaborator

Choose a reason for hiding this comment

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

My suggestion would be to have a dedicated error state for those situations.
Like this: https://www.figma.com/file/ifCrok8cP5ymEYjMa2PIi9/MVP?node-id=2934%3A157297&t=CoRB18ePaVLjZtDq-1

@lukaw3d All other data is valid and relevant so why would we hide it? Is there a threat to it in any kind way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

First shot at approaching the design:
image

src/routes.tsx Outdated
@@ -63,6 +66,7 @@ export const routes: RouteObject[] = [
{
path: `/${paraTime}/transactions`,
element: <TransactionsPage />,
errorElement: <RoutingErrorPage />,
Copy link
Member

Choose a reason for hiding this comment

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

The drawback is that there is no TypeScript-level test to verify that the errorElement (or some other error boundary) is always there

Is there a way to add a top-level error handler?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, in fact it's recommended by React Router. What should be the text? Just a generic unknown error?

@csillag csillag force-pushed the csillag/handle-invalid-page-numbers-with-exceptions branch from 1871cab to 440020b Compare February 10, 2023 18:25
@csillag csillag merged commit 02442f0 into master Feb 13, 2023
@csillag csillag deleted the csillag/handle-invalid-page-numbers-with-exceptions branch February 13, 2023 16:08
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