Improve forge authorization error message for invalid tokens.

Before:

    - not authorized by forge (wildcard)
      - cannot check repository permissions: GET https://codeberg.org/api/v1/repos/whitequark/whitequark.codeberg.page returned 401 Unauthorized

After:

    - not authorized by forge (wildcard)
      - no access to whitequark/whitequark.codeberg.page or invalid token
This commit is contained in:
Catherine
2026-04-22 01:36:25 +00:00
parent 57e9d05c7f
commit d17c645927

View File

@@ -578,6 +578,11 @@ func checkGogsRepositoryPushPermission(baseURL *url.URL, authorization string) e
http.StatusNotFound,
fmt.Sprintf("no repository %s", ownerAndRepo),
}
} else if response.StatusCode == http.StatusUnauthorized {
return AuthError{
http.StatusUnauthorized,
fmt.Sprintf("no access to %s or invalid token", ownerAndRepo),
}
} else if response.StatusCode != http.StatusOK {
return AuthError{
http.StatusServiceUnavailable,