-
Notifications
You must be signed in to change notification settings - Fork 190
Expand file tree
/
Copy pathcreateErrorFieldFromRawError.spec.ts
More file actions
71 lines (68 loc) · 1.96 KB
/
Copy pathcreateErrorFieldFromRawError.spec.ts
File metadata and controls
71 lines (68 loc) · 1.96 KB
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
70
71
import type { TimeStamp, RelativeTime } from '@datadog/js-core/time'
import { ErrorHandling, ErrorSource, type RawError } from '@datadog/browser-core'
import { createErrorFieldFromRawError } from './createErrorFieldFromRawError'
describe('createErrorFieldFromRawError', () => {
const exhaustiveRawError: Required<RawError> = {
startClocks: {
relative: 0 as RelativeTime,
timeStamp: 0 as TimeStamp,
},
source: ErrorSource.LOGGER,
handling: ErrorHandling.HANDLED,
handlingStack: 'Error\n at foo (bar)',
componentStack: 'at Flex',
originalError: new Error('baz'),
type: 'qux',
featureId: 'quux-feature',
message: 'quux',
stack: 'quuz',
causes: [
{
source: ErrorSource.CONSOLE,
type: 'Error',
stack: 'Error: Mid level error',
message: 'Mid level error',
},
{
source: ErrorSource.CONSOLE,
type: 'TypeError',
stack: 'TypeError: Low level error',
message: 'Low level error',
},
],
fingerprint: 'corge',
csp: {
disposition: 'enforce',
},
context: {
foo: 'bar',
},
}
it('creates an error field from a raw error', () => {
expect(createErrorFieldFromRawError(exhaustiveRawError)).toEqual({
message: undefined,
kind: 'qux',
feature_id: 'quux-feature',
stack: 'quuz',
causes: [
{
source: ErrorSource.CONSOLE,
type: 'Error',
stack: 'Error: Mid level error',
message: 'Mid level error',
},
{
source: ErrorSource.CONSOLE,
type: 'TypeError',
stack: 'TypeError: Low level error',
message: 'Low level error',
},
],
fingerprint: 'corge',
handling: ErrorHandling.HANDLED,
})
})
it('includes the message if includeMessage is true', () => {
expect(createErrorFieldFromRawError(exhaustiveRawError, { includeMessage: true }).message).toBe('quux')
})
})