diff options
| author | Paul Buetow <paul@buetow.org> | 2025-06-28 00:36:36 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2025-06-28 00:36:36 +0300 |
| commit | 921782160c1f07577035db56b5461a2edc3b30a8 (patch) | |
| tree | ef8c0bbda6ad3717ac1fae92c366d5335c4f08cf /internal/codeberg | |
| parent | 11e602f35d78b17df52e9e8b389d6419903a340f (diff) | |
feat: improve Codeberg API error handling
Enhanced error messages for Codeberg repository creation failures by:
- Reading and parsing API error response body
- Displaying the actual error message from Codeberg API
- This helped identify permission scope issues (e.g., missing write:user scope)
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat (limited to 'internal/codeberg')
| -rw-r--r-- | internal/codeberg/codeberg.go | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/internal/codeberg/codeberg.go b/internal/codeberg/codeberg.go index 1cf5659..4eaed66 100644 --- a/internal/codeberg/codeberg.go +++ b/internal/codeberg/codeberg.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/json" "fmt" + "io" "net/http" "os" "path/filepath" @@ -226,7 +227,23 @@ func (c *Client) CreateRepo(repoName, description string, private bool) error { defer resp.Body.Close() if resp.StatusCode != http.StatusCreated { - return fmt.Errorf("failed to create repository: status code %d", resp.StatusCode) + // Read the response body to get more detailed error information + body, err := io.ReadAll(resp.Body) + if err != nil { + return fmt.Errorf("failed to create repository: status code %d (could not read response)", resp.StatusCode) + } + + // Try to parse as JSON error response + var errorResp map[string]interface{} + if err := json.Unmarshal(body, &errorResp); err == nil { + // If we can parse the JSON, extract the message + if msg, ok := errorResp["message"].(string); ok { + return fmt.Errorf("failed to create repository: %s (status code %d)", msg, resp.StatusCode) + } + } + + // If we can't parse JSON, return the raw response + return fmt.Errorf("failed to create repository: %s (status code %d)", string(body), resp.StatusCode) } return nil |
