-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Previously, when there was an error on the pages on the console it would crash and nothing would load. This commit introduces an error boundary, making an error message show instead of the blank page. Release note (ui change): New page for when something goes wrong and the page crashes.
- Loading branch information
Showing
7 changed files
with
137 additions
and
11 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
70 changes: 70 additions & 0 deletions
70
pkg/ui/workspaces/db-console/src/views/app/components/errorMessage/errorBoundary.tsx
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,70 @@ | ||
// Copyright 2021 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
import React, { ErrorInfo } from "react"; | ||
import Helmet from "react-helmet"; | ||
import "./errorMessage.styl"; | ||
import SleepyMoonImg from "assets/sleepy-moon.svg"; | ||
|
||
interface ErrorBoundaryProps { | ||
onCatch?: (error: Error, errorInfo: ErrorInfo) => void; | ||
} | ||
|
||
interface ErrorBoundaryState { | ||
hasError: boolean; | ||
error: Error | undefined; | ||
} | ||
|
||
// ErrorBoundary with image and text message. | ||
export default class ErrorBoundary extends React.Component< | ||
ErrorBoundaryProps, | ||
ErrorBoundaryState | ||
> { | ||
constructor(props: ErrorBoundaryProps) { | ||
super(props); | ||
this.state = { | ||
hasError: false, | ||
error: undefined, | ||
}; | ||
} | ||
|
||
static getDerivedStateFromError(error: Error) { | ||
return { hasError: true, error }; | ||
} | ||
|
||
componentDidCatch(error: Error, errorInfo: ErrorInfo) { | ||
// Console.error for developer visibility. | ||
console.error(error); | ||
this.props.onCatch && this.props.onCatch(error, errorInfo); | ||
} | ||
|
||
render() { | ||
if (!this.state.hasError) { | ||
return this.props.children; | ||
} | ||
return ( | ||
<main className="error-message-page"> | ||
<Helmet title="Error" /> | ||
<div className="error-message-page__content"> | ||
<img className="error-message-page__img" src={SleepyMoonImg} /> | ||
<div className="error-message-page__body"> | ||
<div className="error-message-page__message"> | ||
Something went wrong. | ||
</div> | ||
<p> | ||
There is a problem loading the component of this page. Try | ||
refreshing the page. | ||
</p> | ||
</div> | ||
</div> | ||
</main> | ||
); | ||
} | ||
} |
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