Skip to content

Commit

Permalink
[EuiErrorBoundary] Show message in non-Chromium browsers (#4324)
Browse files Browse the repository at this point in the history
* build error message from Error subparts

* CL
  • Loading branch information
thompsongl authored Dec 1, 2020
1 parent 184dcdb commit c4177bc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No public interface changes since `30.5.1`.
**Bug fixes**

- Expose `EuiErrorBoundary` error message not showing in non-Chromium browsers ([#4324](https://github.com/elastic/eui/pull/4324))

## [`30.5.1`](https://github.com/elastic/eui/tree/v30.5.1)

Expand Down
12 changes: 9 additions & 3 deletions src/components/error_boundary/error_boundary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { EuiText } from '../text';

interface EuiErrorBoundaryState {
hasError: boolean;
error?: Error;
error?: string;
}

export type EuiErrorBoundaryProps = CommonProps &
Expand Down Expand Up @@ -55,8 +55,14 @@ export class EuiErrorBoundary extends Component<
this.state = errorState;
}

componentDidCatch(error: Error) {
componentDidCatch({ message, stack }: Error) {
// Display fallback UI
// Only Chrome includes the `message` property as part of `stack`.
// For consistency, rebuild the full error text from the Error subparts.
const idx = stack?.indexOf(message) || -1;
const stackStr = idx > -1 ? stack?.substr(idx + message.length + 1) : stack;
const error = `Error: ${message}
${stackStr}`;
this.setState({
hasError: true,
error,
Expand All @@ -74,7 +80,7 @@ export class EuiErrorBoundary extends Component<
<EuiText size="xs">
<h1>Error</h1>
<pre className="euiErrorBoundary__stack">
<p>{this.state.error && this.state.error.stack}</p>
<p>{this.state.error}</p>
</pre>
</EuiText>
</div>
Expand Down

0 comments on commit c4177bc

Please sign in to comment.