File size: 513 Bytes
c7052c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { addBreadcrumb } from '@sentry/node-core/light';

type SerializableValue =
  | boolean
  | null
  | number
  | string
  | undefined
  | readonly SerializableValue[]
  | { readonly [key: string]: SerializableValue };

export const parseJson = <T = SerializableValue>(subject: string): T => {
  try {
    return JSON.parse(subject);
  } catch (error) {
    addBreadcrumb({
      data: {
        subject,
      },
      level: 'debug',
      message: 'could not parse JSON',
    });

    throw error;
  }
};