mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
refactor(errors): explain failed requests through the SDK
The hints for a missing repository, a pull request number that names an issue and an existing pull request read the API with raw GETs from the app layer. Read them through SDK lookups in services, which reuse the failed request's instance and credential, and let transport only hand out that client. Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
4 files changed
+106
-59
No files matched your search
@@ -232,12 +232,11 @@ func TestAPIErrorLookupRepeatsReadsWithTheFailedCredential(t *testing.T) {
|
||||
var apiErr *APIError
|
||||
require.ErrorAs(t, err, &apiErr)
|
||||
require.Equal(t, server.URL+"/base", apiErr.Instance)
|
||||
var repo struct {
|
||||
FullName string `json:"full_name"`
|
||||
HasIssues bool `json:"has_issues"`
|
||||
}
|
||||
require.Equal(t, http.StatusOK, apiErr.Lookup(context.Background(), "repos/a/b", &repo))
|
||||
require.Equal(t, "a/b", repo.FullName)
|
||||
require.Equal(t, http.StatusNotFound, apiErr.Lookup(context.Background(), "repos/a/missing", nil))
|
||||
require.Zero(t, (&APIError{Status: http.StatusNotFound}).Lookup(context.Background(), "repos/a/b", nil), "errors built without a request cannot look up")
|
||||
lookup := apiErr.LookupClient()
|
||||
require.NotNil(t, lookup)
|
||||
resp, err := lookup.Get(server.URL + "/base/api/v1/repos/a/b")
|
||||
require.NoError(t, err)
|
||||
_ = resp.Body.Close()
|
||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||
require.Nil(t, (&APIError{Status: http.StatusNotFound}).LookupClient(), "errors built without a request cannot look up")
|
||||
}
|
||||
Reference in new issue
Block a user