MCPcopy Index your code
hub / github.com/coder/coder / readBodyAsChatUsageLimitError

Function readBodyAsChatUsageLimitError

codersdk/chats.go:1822–1846  ·  view source on GitHub ↗
(res *http.Response)

Source from the content-addressed store, hash-verified

1820}
1821
1822func readBodyAsChatUsageLimitError(res *http.Response) error {
1823 if res == nil || res.StatusCode != http.StatusConflict {
1824 return ReadBodyAsError(res)
1825 }
1826 defer res.Body.Close()
1827
1828 rawBody, err := io.ReadAll(res.Body)
1829 if err != nil {
1830 return xerrors.Errorf("read body: %w", err)
1831 }
1832
1833 if mimeErr := ExpectJSONMime(res); mimeErr != nil {
1834 return readRawBodyAsError(res, rawBody)
1835 }
1836
1837 var payload ChatUsageLimitExceededResponse
1838 if err := json.NewDecoder(bytes.NewReader(rawBody)).Decode(&payload); err == nil && isChatUsageLimitExceededResponse(payload) {
1839 return &chatUsageLimitExceededError{
1840 err: newResponseError(res, payload.Response),
1841 response: payload,
1842 }
1843 }
1844
1845 return readRawBodyAsError(res, rawBody)
1846}
1847
1848func isChatUsageLimitExceededResponse(resp ChatUsageLimitExceededResponse) bool {
1849 return resp.Message != "" && !resp.ResetsAt.IsZero()

Callers 5

CreateChatMethod · 0.85
CreateChatMessageMethod · 0.85
EditChatMessageMethod · 0.85
RegenerateChatTitleMethod · 0.85
ProposeChatTitleMethod · 0.85

Calls 8

ReadBodyAsErrorFunction · 0.85
ExpectJSONMimeFunction · 0.85
readRawBodyAsErrorFunction · 0.85
newResponseErrorFunction · 0.70
CloseMethod · 0.65
ReadAllMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected