(raw: string)
| 403 | }; |
| 404 | |
| 405 | function statusOfName(raw: string): number | null { |
| 406 | let name = raw.replace(/^(?:HttpStatus|HTTPStatus|StatusCodes|StatusCode|http|status|HttpStatusCode|Status|HTTP_|HTTP)[._]?/, ''); |
| 407 | name = name.replace(/(?:Exception|Error|Response|Result|Async|Http|Status|Code)$/g, '').replace(/^Http(?=[A-Z])/, ''); |
| 408 | const key = name.replace(/[^A-Za-z0-9]/g, '').toLowerCase(); |
| 409 | if (key === '') return null; |
| 410 | if (/^\d{3}$/.test(key)) return Number(key); |
| 411 | const m = /^(?:http)?(\d{3})$/.exec(key) ?? /(?:^|[a-z_])([1-5]\d{2})(?:[a-z_]|$)/.exec(key); |
| 412 | if (m) return Number(m[1]); |
| 413 | if (STATUS_BY_NAME[key] !== undefined) return STATUS_BY_NAME[key]!; |
| 414 | // `UserNotFound`, `InvalidTokenUnauthorized`: the status name ends the class name. |
| 415 | for (const [known, code] of Object.entries(STATUS_BY_NAME)) { |
| 416 | if (known.length >= 6 && key.endsWith(known)) return code; |
| 417 | } |
| 418 | return null; |
| 419 | } |
| 420 | |
| 421 | /** |
| 422 | * The status code a response site sends, when it is literal: the number in |
no test coverage detected