mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 19:11: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
@@ -237,9 +237,10 @@ func (s Pulls) View(ctx context.Context, n int64) (Pull, error) {
|
||||
}
|
||||
|
||||
func (s Pulls) get(ctx context.Context, n int64) (*gitea.PullRequest, error) {
|
||||
return repoCall(ctx, s.Client, s.Repository, func(ctx context.Context, c *gitea.Client, owner, name string) (*gitea.PullRequest, *gitea.Response, error) {
|
||||
item, err := repoCall(ctx, s.Client, s.Repository, func(ctx context.Context, c *gitea.Client, owner, name string) (*gitea.PullRequest, *gitea.Response, error) {
|
||||
return c.PullRequests.GetPullRequest(ctx, owner, name, n)
|
||||
})
|
||||
return item, Classify(err, "pull request", "#"+strconv.FormatInt(n, 10), s.Repository)
|
||||
}
|
||||
|
||||
// ListOpen returns every open pull request in the repository.
|
||||
@@ -255,7 +256,7 @@ func (s Pulls) Create(ctx context.Context, opts PullOptions) (Pull, error) {
|
||||
// TODO(sdk): CreatePullRequestOption lacks allow_maintainer_edit.
|
||||
var pull gitea.PullRequest
|
||||
if err := sendJSON(ctx, s.Client, http.MethodPost, "repos/"+s.Repository+"/pulls", opts, &pull); err != nil {
|
||||
return Pull{}, err
|
||||
return Pull{}, Classify(err, "pull request", "", s.Repository)
|
||||
}
|
||||
return pullFrom(&pull), nil
|
||||
}
|
||||
@@ -308,9 +309,10 @@ func (s Pulls) Edit(ctx context.Context, n int64, opts PullEdit) (Pull, error) {
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
return repoConvert(ctx, s.Client, s.Repository, pullFrom, func(ctx context.Context, c *gitea.Client, owner, name string) (*gitea.PullRequest, *gitea.Response, error) {
|
||||
item, err := repoConvert(ctx, s.Client, s.Repository, pullFrom, func(ctx context.Context, c *gitea.Client, owner, name string) (*gitea.PullRequest, *gitea.Response, error) {
|
||||
return c.PullRequests.EditPullRequest(ctx, owner, name, n, editPullOption(opts))
|
||||
})
|
||||
return item, Classify(err, "pull request", "#"+strconv.FormatInt(n, 10), s.Repository)
|
||||
}
|
||||
|
||||
func editPullOption(opts PullEdit) gitea.EditPullRequestOption {
|
||||
@@ -438,8 +440,9 @@ func (s Pulls) Merge(ctx context.Context, n int64, opts MergeOptions) error {
|
||||
_, resp, err := c.PullRequests.MergePullRequest(ctx, owner, name, n, option)
|
||||
return resp, err
|
||||
})
|
||||
key := "#" + strconv.FormatInt(n, 10)
|
||||
if refused, ok := errors.AsType[*transport.APIError](err); !ok || refused.Status != http.StatusMethodNotAllowed {
|
||||
return err
|
||||
return Classify(err, "pull request", key, s.Repository)
|
||||
}
|
||||
var reason string
|
||||
switch {
|
||||
@@ -452,7 +455,7 @@ func (s Pulls) Merge(ctx context.Context, n int64, opts MergeOptions) error {
|
||||
case !pull.Mergeable:
|
||||
reason = "has conflicting files or is otherwise not mergeable"
|
||||
default:
|
||||
return err
|
||||
return Classify(err, "pull request", key, s.Repository)
|
||||
}
|
||||
return fmt.Errorf("pull request #%d %s: %w", n, reason, err)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user