mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
refactor: drop the URL-based error classifier and hint lookups
Errors are named by the service call that failed: Classify, NotFoundError and ConflictError at the call site. Remove the endpoint parser that guessed the resource from the request path, and the follow-up reads the explainer made at error time (repository state, issue-vs-pull-request, the existing pull request's URL) together with the credentialed transport each API error carried for them. Calls that the endpoint parser covered and the services did not now classify themselves: issues, pull requests, reviews, comments, releases, branches, wiki pages, repositories, organizations and SSH keys. Unclassified failures fall back to the generic "not found (HTTP 404 GET ...)" text. Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
20 files changed
+129
-495
No files matched your search
@@ -6,6 +6,7 @@ package services
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"strconv"
|
||||
|
||||
gitea "gitea.dev/sdk"
|
||||
"gitea.dev/tea/internal/transport"
|
||||
@@ -45,7 +46,7 @@ func (s SSHKeys) View(ctx context.Context, id int64) (SSHKey, error) {
|
||||
return c.Users.GetPublicKey(ctx, id)
|
||||
})
|
||||
if err != nil {
|
||||
return SSHKey{}, err
|
||||
return SSHKey{}, Classify(err, "SSH key", strconv.FormatInt(id, 10), "")
|
||||
}
|
||||
return sshKeyFrom(key), nil
|
||||
}
|
||||
@@ -56,14 +57,15 @@ func (s SSHKeys) Create(ctx context.Context, title, key string) (SSHKey, error)
|
||||
return c.Users.CreatePublicKey(ctx, gitea.CreateKeyOption{Title: title, Key: key})
|
||||
})
|
||||
if err != nil {
|
||||
return SSHKey{}, err
|
||||
return SSHKey{}, Classify(err, "SSH key", "", "")
|
||||
}
|
||||
return sshKeyFrom(created), nil
|
||||
}
|
||||
|
||||
// Delete removes only the selected public key.
|
||||
func (s SSHKeys) Delete(ctx context.Context, id int64) error {
|
||||
return do(ctx, s.Client, func(ctx context.Context, c *gitea.Client) (*gitea.Response, error) {
|
||||
err := do(ctx, s.Client, func(ctx context.Context, c *gitea.Client) (*gitea.Response, error) {
|
||||
return c.Users.DeletePublicKey(ctx, id)
|
||||
})
|
||||
return Classify(err, "SSH key", strconv.FormatInt(id, 10), "")
|
||||
}
|
||||
Reference in new issue
Block a user