(statusCode: number, statusRange: string)
| 493 | * Returns `true` if the status code falls within the range, and `false` otherwise. |
| 494 | */ |
| 495 | const isStatusCodeInRange = (statusCode: number, statusRange: string): boolean => { |
| 496 | if (statusRange === "all") { |
| 497 | return true; |
| 498 | } |
| 499 | |
| 500 | if (statusRange.includes(",")) { |
| 501 | const statusCodes = statusRange.split(",").map((s) => s.trim()); |
| 502 | |
| 503 | return statusCodes.some((s) => isStatusCodeInRange(statusCode, s)); |
| 504 | } |
| 505 | |
| 506 | const [start, end] = statusRange.split("-"); |
| 507 | |
| 508 | if (end) { |
| 509 | return statusCode >= parseInt(start, 10) && statusCode <= parseInt(end, 10); |
| 510 | } |
| 511 | |
| 512 | if (start.endsWith("xx")) { |
| 513 | const prefix = start.slice(0, -2); |
| 514 | const statusCodePrefix = Math.floor(statusCode / 100).toString(); |
| 515 | return statusCodePrefix === prefix; |
| 516 | } |
| 517 | |
| 518 | const statusCodeString = statusCode.toString(); |
| 519 | const rangePrefix = start.slice(0, -1); |
| 520 | |
| 521 | if (start.endsWith("x") && statusCodeString.startsWith(rangePrefix)) { |
| 522 | return true; |
| 523 | } |
| 524 | |
| 525 | return statusCode === parseInt(start, 10); |
| 526 | }; |
| 527 | |
| 528 | const createAttributesFromHeaders = (headers: Headers): Attributes => { |
| 529 | const attributes: Attributes = {}; |
no test coverage detected
searching dependent graphs…