ClassifyStatusCode 分类状态码
(statusCode int, accessible bool)
| 38 | |
| 39 | // ClassifyStatusCode 分类状态码 |
| 40 | func ClassifyStatusCode(statusCode int, accessible bool) string { |
| 41 | if !accessible { |
| 42 | return StatusCodeCategoryNetwork |
| 43 | } |
| 44 | |
| 45 | // 安全的状态码 |
| 46 | switch statusCode { |
| 47 | case 200, 301, 302, 404: |
| 48 | return StatusCodeCategorySafe |
| 49 | } |
| 50 | |
| 51 | // 排除的状态码 |
| 52 | switch statusCode { |
| 53 | case 401, 403, 407, 408, 429: |
| 54 | return StatusCodeCategoryExcluded |
| 55 | } |
| 56 | |
| 57 | // 5xx 系列 |
| 58 | if statusCode >= 500 && statusCode < 600 { |
| 59 | return StatusCodeCategoryExcluded |
| 60 | } |
| 61 | |
| 62 | // 其他状态码也归类为排除 |
| 63 | return StatusCodeCategoryExcluded |
| 64 | } |
| 65 | |
| 66 | // IsStatusCodeSafe 检查状态码是否安全 |
| 67 | func IsStatusCodeSafe(statusCode int) bool { |
no outgoing calls
no test coverage detected