-
Notifications
You must be signed in to change notification settings - Fork 430
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #735 from blockscout/blocks/consensus-lost
display error when block has lost consensus
- Loading branch information
Showing
7 changed files
with
80 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export default function getErrorCause(error: Error | undefined): Record<string, unknown> | undefined { | ||
return ( | ||
error && 'cause' in error && | ||
typeof error.cause === 'object' && error.cause !== null && | ||
error.cause as Record<string, unknown> | ||
) || | ||
undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
import getErrorCause from './getErrorCause'; | ||
|
||
export default function getErrorStatusCode(error: Error | undefined): number | undefined { | ||
return ( | ||
error && 'cause' in error && | ||
typeof error.cause === 'object' && error.cause !== null && | ||
'status' in error.cause && typeof error.cause.status === 'number' && | ||
error.cause.status | ||
) || | ||
undefined; | ||
const cause = getErrorCause(error); | ||
return cause && 'status' in cause && typeof cause.status === 'number' ? cause.status : undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import type { ResourceError } from 'lib/api/resources'; | ||
|
||
import getErrorCause from './getErrorCause'; | ||
|
||
export default function getResourceErrorPayload<Payload = Record<string, unknown>>(error: Error | undefined): ResourceError<Payload>['payload'] | undefined { | ||
const cause = getErrorCause(error); | ||
return cause && 'payload' in cause ? cause.payload as ResourceError<Payload>['payload'] : undefined; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Box, Button, Heading, Icon, chakra } from '@chakra-ui/react'; | ||
import { route } from 'nextjs-routes'; | ||
import React from 'react'; | ||
|
||
import icon404 from 'icons/error-pages/404.svg'; | ||
|
||
interface Props { | ||
hash?: string; | ||
className?: string; | ||
} | ||
|
||
const AppErrorBlockConsensus = ({ hash, className }: Props) => { | ||
return ( | ||
<Box className={ className }> | ||
<Icon as={ icon404 } width="200px" height="auto"/> | ||
<Heading mt={ 8 } size="2xl" fontFamily="body">Block has lost consensus</Heading> | ||
<Button | ||
mt={ 8 } | ||
size="lg" | ||
variant="outline" | ||
as="a" | ||
href={ hash ? route({ pathname: '/block/[height]', query: { height: hash } }) : route({ pathname: '/' }) } | ||
> | ||
{ hash ? 'View reorg' : 'Back to home' } | ||
</Button> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default chakra(AppErrorBlockConsensus); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters