# All files / src/Vue helper.ts

13.33% Statements 4/30
0% Branches 0/36
0% Functions 0/3
13.33% Lines 4/30

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
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    701x
    1x

    1x

    1x

     import { getBigVersion, getLocationHref, getTimestamp, variableTypeDetection } from '../utils/index'
    import { ERRORTYPES, BREADCRUMBTYPES } from '../common/constant'
    import { ViewModel, VueInstance } from './types'
    import { breadcrumb, transportData } from '../core/index'
    import { ReportDataType } from '../types/transportData'
    import { Severity } from '../utils/Severity'

    export function handleVueError(err: Error, vm: ViewModel, info: string, level: Severity, breadcrumbLevel: Severity, Vue: VueInstance): void {
      const version = Vue?.version
      let data: ReportDataType = {
        type: ERRORTYPES.VUE_ERROR,
        message: `${err.message}(${info})`,
        level,
        url: getLocationHref(),
        name: err.name,
        stack: err.stack || [],
        time: getTimestamp()
      }
      if (variableTypeDetection.isString(version)) {
        console.log('getBigVersion', getBigVersion(version))
        switch (getBigVersion(version)) {
          case 2:
            data = { ...data, ...vue2VmHandler(vm) }
            break
          case 3:
            data = { ...data, ...vue3VmHandler(vm) }
            break
          default:
            return
            break
        }
      }
      breadcrumb.push({
        type: BREADCRUMBTYPES.VUE,
        category: breadcrumb.getCategory(BREADCRUMBTYPES.VUE),
        data,
        level: breadcrumbLevel
      })
      transportData.send(data)
    }
    function vue2VmHandler(vm: ViewModel) {
      let componentName = ''
      if (vm.$root === vm) {
        componentName = 'root'
      } else {
        const name = vm._isVue ? (vm.$options && vm.$options.name) || (vm.$options && vm.$options._componentTag) : vm.name
        componentName =
          (name ? 'component <' + name + '>' : 'anonymous component') +
          (vm._isVue && vm.$options && vm.$options.__file ? ' at ' + (vm.$options && vm.$options.__file) : '')
      }
      return {
        componentName,
        propsData: vm.$options && vm.$options.propsData
      }
    }
    function vue3VmHandler(vm: ViewModel) {
      let componentName = ''
      if (vm.$root === vm) {
        componentName = 'root'
      } else {
        console.log(vm.$options)
        const name = vm.$options && vm.$options.name
        componentName = name ? 'component <' + name + '>' : 'anonymous component'
      }
      return {
        componentName,
        propsData: vm.$props
      }
    }