feat: add PR diff, PR review, and structured error handling commands
This commit is contained in:
parent
3db03ed5e2
commit
50191cc542
10 changed files with 1008 additions and 13 deletions
|
|
@ -76,7 +76,11 @@ func (c *Client) GetJSON(path string, result any) error {
|
|||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
return fmt.Errorf("API request failed with status %d: %s", resp.StatusCode, string(body))
|
||||
return &APIError{
|
||||
StatusCode: resp.StatusCode,
|
||||
Body: string(body),
|
||||
Message: fmt.Sprintf("API request failed with status %d: %s", resp.StatusCode, string(body)),
|
||||
}
|
||||
}
|
||||
|
||||
if err := json.NewDecoder(resp.Body).Decode(result); err != nil {
|
||||
|
|
@ -134,7 +138,11 @@ func (c *Client) DoJSON(method string, path string, body any, result any) (int,
|
|||
|
||||
if resp.StatusCode != http.StatusOK && resp.StatusCode != http.StatusCreated && resp.StatusCode != http.StatusNoContent {
|
||||
bodyBytes, _ := io.ReadAll(resp.Body)
|
||||
return resp.StatusCode, fmt.Errorf("API request failed with status %d: %s", resp.StatusCode, string(bodyBytes))
|
||||
return resp.StatusCode, &APIError{
|
||||
StatusCode: resp.StatusCode,
|
||||
Body: string(bodyBytes),
|
||||
Message: fmt.Sprintf("API request failed with status %d: %s", resp.StatusCode, string(bodyBytes)),
|
||||
}
|
||||
}
|
||||
|
||||
if result != nil && resp.StatusCode != http.StatusNoContent {
|
||||
|
|
@ -171,7 +179,11 @@ func (c *Client) GetRawLog(url string) (string, error) {
|
|||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
return "", fmt.Errorf("API request failed with status %d: %s", resp.StatusCode, string(body))
|
||||
return "", &APIError{
|
||||
StatusCode: resp.StatusCode,
|
||||
Body: string(body),
|
||||
Message: fmt.Sprintf("API request failed with status %d: %s", resp.StatusCode, string(body)),
|
||||
}
|
||||
}
|
||||
|
||||
bodyBytes, err := io.ReadAll(resp.Body)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue