(error, fallbackStage = "unknown")
| 215 | } |
| 216 | |
| 217 | function normalizeError(error, fallbackStage = "unknown") { |
| 218 | if (!error) { |
| 219 | return { |
| 220 | errorStage: fallbackStage, |
| 221 | errorClass: "Error", |
| 222 | errorCode: null, |
| 223 | errorMessage: "Unknown error", |
| 224 | }; |
| 225 | } |
| 226 | |
| 227 | if (isOutboundPolicyError(error)) { |
| 228 | const serializedPolicyError = serializeOutboundPolicyError(error); |
| 229 | return { |
| 230 | errorStage: "policy", |
| 231 | errorClass: error.name || "OutboundPolicyError", |
| 232 | errorCode: error.code || serializedPolicyError?.code || null, |
| 233 | errorMessage: truncateString( |
| 234 | serializedPolicyError?.message || error.message || String(error), |
| 235 | ERROR_MESSAGE_LENGTH |
| 236 | ), |
| 237 | }; |
| 238 | } |
| 239 | |
| 240 | const stage = error.auditStage || fallbackStage; |
| 241 | const errorCode = error.code |
| 242 | || (error.original && error.original.code) |
| 243 | || error.statusCode |
| 244 | || null; |
| 245 | |
| 246 | return { |
| 247 | errorStage: stage, |
| 248 | errorClass: error.name || typeof error, |
| 249 | errorCode: errorCode ? String(errorCode) : null, |
| 250 | errorMessage: truncateString(error.message || String(error), ERROR_MESSAGE_LENGTH), |
| 251 | }; |
| 252 | } |
| 253 | |
| 254 | function getDurationMs(startedAt, finishedAt) { |
| 255 | const normalizedStartedAt = hydrateDate(startedAt); |
no test coverage detected