summaryrefslogtreecommitdiff
path: root/internal/codeberg
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2025-06-28 00:36:36 +0300
committerPaul Buetow <paul@buetow.org>2025-06-28 00:36:36 +0300
commit921782160c1f07577035db56b5461a2edc3b30a8 (patch)
treeef8c0bbda6ad3717ac1fae92c366d5335c4f08cf /internal/codeberg
parent11e602f35d78b17df52e9e8b389d6419903a340f (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.go19
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