xrpc,knotserver: refactor RepoNotFound errors #564

merged
opened by oppi.li targeting master from push-yqnqquktxqpx
Changed files
+11 -24
knotserver
xrpc
errors
+1 -4
knotserver/xrpc/repo_branch.go
···
gr, err := git.PlainOpen(repoPath)
if err != nil {
-
writeError(w, xrpcerr.NewXrpcError(
-
xrpcerr.WithTag("RepoNotFound"),
-
xrpcerr.WithMessage("repository not found"),
-
), http.StatusNotFound)
return
}
···
gr, err := git.PlainOpen(repoPath)
if err != nil {
+
writeError(w, xrpcerr.RepoNotFoundError, http.StatusNoContent)
return
}
+1 -4
knotserver/xrpc/repo_branches.go
···
gr, err := git.PlainOpen(repoPath)
if err != nil {
-
writeError(w, xrpcerr.NewXrpcError(
-
xrpcerr.WithTag("RepoNotFound"),
-
xrpcerr.WithMessage("repository not found"),
-
), http.StatusNotFound)
return
}
···
gr, err := git.PlainOpen(repoPath)
if err != nil {
+
writeError(w, xrpcerr.RepoNotFoundError, http.StatusNoContent)
return
}
+1 -4
knotserver/xrpc/repo_compare.go
···
gr, err := git.PlainOpen(repoPath)
if err != nil {
-
writeError(w, xrpcerr.NewXrpcError(
-
xrpcerr.WithTag("RepoNotFound"),
-
xrpcerr.WithMessage("repository not found"),
-
), http.StatusNotFound)
return
}
···
gr, err := git.PlainOpen(repoPath)
if err != nil {
+
writeError(w, xrpcerr.RepoNotFoundError, http.StatusNoContent)
return
}
+1 -4
knotserver/xrpc/repo_tags.go
···
gr, err := git.PlainOpen(repoPath)
if err != nil {
x.Logger.Error("failed to open", "error", err)
-
writeError(w, xrpcerr.NewXrpcError(
-
xrpcerr.WithTag("RepoNotFound"),
-
xrpcerr.WithMessage("repository not found"),
-
), http.StatusNoContent)
return
}
···
gr, err := git.PlainOpen(repoPath)
if err != nil {
x.Logger.Error("failed to open", "error", err)
+
writeError(w, xrpcerr.RepoNotFoundError, http.StatusNoContent)
return
}
+2 -8
knotserver/xrpc/xrpc.go
···
// Construct repository path using the same logic as didPath
didRepoPath, err := securejoin.SecureJoin(did, repoName)
if err != nil {
-
return "", xrpcerr.NewXrpcError(
-
xrpcerr.WithTag("RepoNotFound"),
-
xrpcerr.WithMessage("failed to access repository"),
-
)
}
repoPath, err := securejoin.SecureJoin(x.Config.Repo.ScanPath, didRepoPath)
if err != nil {
-
return "", xrpcerr.NewXrpcError(
-
xrpcerr.WithTag("RepoNotFound"),
-
xrpcerr.WithMessage("failed to access repository"),
-
)
}
return repoPath, nil
···
// Construct repository path using the same logic as didPath
didRepoPath, err := securejoin.SecureJoin(did, repoName)
if err != nil {
+
return "", xrpcerr.RepoNotFoundError
}
repoPath, err := securejoin.SecureJoin(x.Config.Repo.ScanPath, didRepoPath)
if err != nil {
+
return "", xrpcerr.RepoNotFoundError
}
return repoPath, nil
+5
xrpc/errors/errors.go
···
WithMessage("owner not set for this service"),
)
var AuthError = func(err error) XrpcError {
return NewXrpcError(
WithTag("Auth"),
···
WithMessage("owner not set for this service"),
)
+
var RepoNotFoundError = NewXrpcError(
+
WithTag("RepoNotFound"),
+
WithMessage("failed to access repository"),
+
)
+
var AuthError = func(err error) XrpcError {
return NewXrpcError(
WithTag("Auth"),