Skip to content

Commit fc96a32

Browse files
authored
feat: Add UI crash logs (nervosnetwork#3328)
* feat: Add UI crash logs * fix
1 parent 0d4c967 commit fc96a32

File tree

2 files changed

+21
-8
lines changed
  • packages
    • neuron-ui/src/components/ErrorBoundary
    • neuron-wallet/src/controllers

2 files changed

+21
-8
lines changed

packages/neuron-ui/src/components/ErrorBoundary/index.tsx

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
1-
import React, { Component } from 'react'
1+
import React, { Component, ErrorInfo, ReactNode } from 'react'
22
import { Stack } from 'office-ui-fabric-react'
33
import Spinner from 'widgets/Spinner'
44
import { handleViewError } from 'services/remote'
55

6-
const handleError = (error: Error) => {
7-
handleViewError(error.toString())
6+
const handleError = (error: Error, errorInfo?: ErrorInfo) => {
7+
handleViewError(
8+
JSON.stringify([
9+
`UI crash: ${error.message}`,
10+
{
11+
stack: error.stack,
12+
componentStack: errorInfo?.componentStack || 'N/A',
13+
},
14+
])
15+
)
816
if (import.meta.env.MODE !== 'development') {
917
window.location.reload()
1018
}
11-
return { hasError: true }
1219
}
1320

14-
class ErrorBoundary extends Component<{ children: React.ReactChild }, { hasError: boolean }> {
15-
constructor(props: { children: React.ReactChild }) {
21+
class ErrorBoundary extends Component<{ children: ReactNode }, { hasError: boolean }> {
22+
constructor(props: { children: ReactNode }) {
1623
super(props)
1724
this.state = {
1825
hasError: false,
@@ -23,8 +30,9 @@ class ErrorBoundary extends Component<{ children: React.ReactChild }, { hasError
2330
return handleError(error)
2431
}
2532

26-
public componentDidCatch(error: Error) {
27-
this.setState(handleError(error))
33+
public componentDidCatch(error: Error, errorInfo: ErrorInfo) {
34+
handleError(error, errorInfo)
35+
this.setState({ hasError: true })
2836
}
2937

3038
render() {

packages/neuron-wallet/src/controllers/api.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@ export default class ApiController {
284284
if (env.isDevMode) {
285285
console.error(error)
286286
}
287+
try {
288+
logger.error(JSON.parse(error))
289+
} catch (e) {
290+
logger.error(error)
291+
}
287292
})
288293

289294
handle('set-locale', async (_, locale: Locale) => {

0 commit comments

Comments
 (0)