diff --git a/knotserver/xrpc/repo_branch.go b/knotserver/xrpc/repo_branch.go --- a/knotserver/xrpc/repo_branch.go +++ b/knotserver/xrpc/repo_branch.go @@ -32,10 +32,7 @@ gr, err := git.PlainOpen(repoPath) if err != nil { - writeError(w, xrpcerr.NewXrpcError( - xrpcerr.WithTag("RepoNotFound"), - xrpcerr.WithMessage("repository not found"), - ), http.StatusNotFound) + writeError(w, xrpcerr.RepoNotFoundError, http.StatusNoContent) return } diff --git a/knotserver/xrpc/repo_branches.go b/knotserver/xrpc/repo_branches.go --- a/knotserver/xrpc/repo_branches.go +++ b/knotserver/xrpc/repo_branches.go @@ -31,10 +31,7 @@ gr, err := git.PlainOpen(repoPath) if err != nil { - writeError(w, xrpcerr.NewXrpcError( - xrpcerr.WithTag("RepoNotFound"), - xrpcerr.WithMessage("repository not found"), - ), http.StatusNotFound) + writeError(w, xrpcerr.RepoNotFoundError, http.StatusNoContent) return } diff --git a/knotserver/xrpc/repo_compare.go b/knotserver/xrpc/repo_compare.go --- a/knotserver/xrpc/repo_compare.go +++ b/knotserver/xrpc/repo_compare.go @@ -38,10 +38,7 @@ gr, err := git.PlainOpen(repoPath) if err != nil { - writeError(w, xrpcerr.NewXrpcError( - xrpcerr.WithTag("RepoNotFound"), - xrpcerr.WithMessage("repository not found"), - ), http.StatusNotFound) + writeError(w, xrpcerr.RepoNotFoundError, http.StatusNoContent) return } diff --git a/knotserver/xrpc/repo_tags.go b/knotserver/xrpc/repo_tags.go --- a/knotserver/xrpc/repo_tags.go +++ b/knotserver/xrpc/repo_tags.go @@ -33,10 +33,7 @@ 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) + writeError(w, xrpcerr.RepoNotFoundError, http.StatusNoContent) return } diff --git a/knotserver/xrpc/xrpc.go b/knotserver/xrpc/xrpc.go --- a/knotserver/xrpc/xrpc.go +++ b/knotserver/xrpc/xrpc.go @@ -101,18 +101,12 @@ // 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"), - ) + return "", xrpcerr.RepoNotFoundError } 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 "", xrpcerr.RepoNotFoundError } return repoPath, nil diff --git a/xrpc/errors/errors.go b/xrpc/errors/errors.go --- a/xrpc/errors/errors.go +++ b/xrpc/errors/errors.go @@ -56,6 +56,11 @@ 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"),