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:
bircni committed 2026-10-12 10:40:45 +02:00
1 parent ea13c9e4f5
commit 27e39ec4be
20 files changed
+129 -495

No files matched your search

+7 -3
View File
@@ -6,6 +6,7 @@ package services
import (
"context"
"net/http"
"strconv"
"strings"
"time"
@@ -144,19 +145,21 @@ func filterValues(value string) []string {
// View retrieves one issue.
func (s Issues) View(ctx context.Context, number int64) (Issue, error) {
return repoConvert(ctx, s.Client, s.Repository, discussionFrom, func(ctx context.Context, c *gitea.Client, owner, repo string) (*gitea.Issue, *gitea.Response, error) {
item, err := repoConvert(ctx, s.Client, s.Repository, discussionFrom, func(ctx context.Context, c *gitea.Client, owner, repo string) (*gitea.Issue, *gitea.Response, error) {
return c.Issues.GetIssue(ctx, owner, repo, number)
})
return item, Classify(err, "issue", "#"+strconv.FormatInt(number, 10), s.Repository)
}
// Create opens an issue.
func (s Issues) Create(ctx context.Context, options IssueOptions) (Issue, error) {
return repoConvert(ctx, s.Client, s.Repository, discussionFrom, func(ctx context.Context, c *gitea.Client, owner, repo string) (*gitea.Issue, *gitea.Response, error) {
item, err := repoConvert(ctx, s.Client, s.Repository, discussionFrom, func(ctx context.Context, c *gitea.Client, owner, repo string) (*gitea.Issue, *gitea.Response, error) {
return c.Issues.CreateIssue(ctx, owner, repo, gitea.CreateIssueOption{
Title: options.Title, Body: options.Body, Ref: options.Ref, Assignees: options.Assignees,
Deadline: options.Deadline, Milestone: options.Milestone, Labels: options.Labels,
})
})
return item, Classify(err, "issue", "", s.Repository)
}
// SetState updates only the selected issue state.
@@ -166,7 +169,8 @@ func (s Issues) SetState(ctx context.Context, number int64, state string) (Issue
}
func (s Issues) edit(ctx context.Context, number int64, opts gitea.EditIssueOption) (Issue, error) {
return repoConvert(ctx, s.Client, s.Repository, discussionFrom, func(ctx context.Context, c *gitea.Client, owner, repo string) (*gitea.Issue, *gitea.Response, error) {
item, err := repoConvert(ctx, s.Client, s.Repository, discussionFrom, func(ctx context.Context, c *gitea.Client, owner, repo string) (*gitea.Issue, *gitea.Response, error) {
return c.Issues.EditIssue(ctx, owner, repo, number, opts)
})
return item, Classify(err, "issue", "#"+strconv.FormatInt(number, 10), s.Repository)
}