(cmd: Command)
| 109 | * duration, and truncated previews of request/response bodies. |
| 110 | */ |
| 111 | export function summarizeNetworkEntry(cmd: Command): object { |
| 112 | const p = cmd.payload as any |
| 113 | const requestData = p?.request?.data != null |
| 114 | ? truncateValue(p.request.data, MAX_BODY_PREVIEW_CHARS) |
| 115 | : undefined |
| 116 | const responseBody = typeof p?.response?.body === "string" |
| 117 | ? (p.response.body.length > MAX_BODY_PREVIEW_CHARS |
| 118 | ? p.response.body.slice(0, MAX_BODY_PREVIEW_CHARS) + "..." |
| 119 | : p.response.body) |
| 120 | : p?.response?.body != null |
| 121 | ? truncateValue(p.response.body, MAX_BODY_PREVIEW_CHARS) |
| 122 | : undefined |
| 123 | |
| 124 | return { |
| 125 | messageId: cmd.messageId, |
| 126 | clientId: cmd.clientId, |
| 127 | date: cmd.date, |
| 128 | duration: p?.duration, |
| 129 | request: { |
| 130 | method: p?.request?.method, |
| 131 | url: p?.request?.url, |
| 132 | headers: p?.request?.headers, |
| 133 | data: requestData, |
| 134 | }, |
| 135 | response: { |
| 136 | status: p?.response?.status, |
| 137 | headers: p?.response?.headers, |
| 138 | body: responseBody, |
| 139 | }, |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | /** Truncate any value to a compact JSON preview. */ |
| 144 | function truncateValue(value: unknown, limit: number): string { |
no test coverage detected