# All files / src/React index.ts

41.67% Statements 5/12
0% Branches 0/2
0% Functions 0/1
41.67% Lines 5/12

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    271x
    1x
    1x
    1x

    1x

     import { BREADCRUMBTYPES, ERRORTYPES } from '../common/constant'
    import { isError, extractErrorStack } from '../utils/index'
    import { Severity } from '../utils/Severity'
    import { breadcrumb, transportData } from '../core/index'
    import { ReportDataType } from '../types/index'

    /**
     * 收集react ErrorBoundary中的错误对象
     * 需要用户手动在componentDidCatch中设置
     * @param ex ErrorBoundary中的componentDidCatch的一个参数error
     */
    export function errorBoundaryReport(ex: any): void {
      if (!isError(ex)) {
        console.warn('传入的react error不是一个object Error')
        return
      }
      const error = extractErrorStack(ex, Severity.Normal) as ReportDataType
      error.type = ERRORTYPES.REACT_ERROR
      breadcrumb.push({
        type: BREADCRUMBTYPES.REACT,
        category: breadcrumb.getCategory(BREADCRUMBTYPES.REACT),
        data: `${error.name}: ${error.message}`,
        level: Severity.fromString(error.level)
      })
      transportData.send(error)
    }