MCPcopy
hub / github.com/larksuite/cli / httpStatusError

Function httpStatusError

internal/client/response.go:49–62  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

47// status >= 400 must not be swallowed — a non-JSON body, an unparseable body,
48// or a JSON body whose business code is 0.
49func 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).

Callers 1

HandleResponseFunction · 0.70

Calls 4

TruncateStrWithEllipsisFunction · 0.92
NewNetworkErrorFunction · 0.92
NewAPIErrorFunction · 0.92
WithCodeMethod · 0.45

Tested by

no test coverage detected