httpStatusError classifies an HTTP error response by status when the body carries no usable business error: 5xx → NetworkError (server tier), 404 → APIError/not_found, any other 4xx → APIError/unknown. Used wherever a status >= 400 must not be swallowed — a non-JSON body, an unparseable body, or a J
(status int, rawBody []byte)
| 47 | // status >= 400 must not be swallowed — a non-JSON body, an unparseable body, |
| 48 | // or a JSON body whose business code is 0. |
| 49 | func httpStatusError(status int, rawBody []byte) error { |
| 50 | body := util.TruncateStrWithEllipsis(strings.TrimSpace(string(rawBody)), 500) |
| 51 | if status >= 500 { |
| 52 | return errs.NewNetworkError(errs.SubtypeNetworkServer, |
| 53 | "HTTP %d: %s", status, body). |
| 54 | WithCode(status) |
| 55 | } |
| 56 | subtype := errs.SubtypeUnknown |
| 57 | if status == 404 { |
| 58 | subtype = errs.SubtypeNotFound |
| 59 | } |
| 60 | return errs.NewAPIError(subtype, "HTTP %d: %s", status, body). |
| 61 | WithCode(status) |
| 62 | } |
| 63 | |
| 64 | // HandleResponse routes a raw *larkcore.ApiResp to the appropriate output: |
| 65 | // 1. If Content-Type is JSON, check for business errors first (even with --output). |
no test coverage detected