🌳
pt0/serverF/throwErrorF/pterrJsonF.mts
1export type pterrEnvCtx = {
2 gpIsProd?: boolean | null
3 appname?: string
4 deploymentName?: string
5 git_sha?: string
6 hostname?: string
7 deployEp?: string
8 gpSiteHost?: string
9 cluster_name?: string
12export type pterrErrCtx = {
13 message?: string
14 errHash?: string
15 backoffNo?: number
16 numSilenced?: number
17 isRlSilenced?: boolean
18 silencedSamples?: unknown[]
21export type pterrJson = {
22 envCtx?: pterrEnvCtx
23 reqCtx?: Record<string, unknown>
24 errCtx?: pterrErrCtx
25 uniqDebugH?: Record<string, unknown>
26 dumpDebugH?: Record<string, unknown>
27 clientStackA?: string[]
28 componentStackA?: string[]
29 smResolutionFailed?: boolean
32export const parsePterrJson = (bodyRaw: string): pterrJson | undefined => {
33 const decoded = bodyRaw
34 .replace(/=\r?\n/g, '')
35 .replace(/=([0-9A-F]{2})/gi, (_, hex: string) => String.fromCharCode(parseInt(hex, 16)))
36 const match = decoded.match(/---PTERR-JSON---\r?\n([\s\S]*?)\r?\n---\/PTERR-JSON---/)
37 if (!match) return undefined
38 try {
39 return JSON.parse(match[1].replace(/\r/g, ''))
40 } catch {
41 return undefined
42 }