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
··· 32 33 gr, err := git.PlainOpen(repoPath) 34 if err != nil { 35 - writeError(w, xrpcerr.NewXrpcError( 36 - xrpcerr.WithTag("RepoNotFound"), 37 - xrpcerr.WithMessage("repository not found"), 38 - ), http.StatusNotFound) 39 return 40 } 41
··· 32 33 gr, err := git.PlainOpen(repoPath) 34 if err != nil { 35 + writeError(w, xrpcerr.RepoNotFoundError, http.StatusNoContent) 36 return 37 } 38
+1 -4
knotserver/xrpc/repo_branches.go
··· 31 32 gr, err := git.PlainOpen(repoPath) 33 if err != nil { 34 - writeError(w, xrpcerr.NewXrpcError( 35 - xrpcerr.WithTag("RepoNotFound"), 36 - xrpcerr.WithMessage("repository not found"), 37 - ), http.StatusNotFound) 38 return 39 } 40
··· 31 32 gr, err := git.PlainOpen(repoPath) 33 if err != nil { 34 + writeError(w, xrpcerr.RepoNotFoundError, http.StatusNoContent) 35 return 36 } 37
+1 -4
knotserver/xrpc/repo_compare.go
··· 38 39 gr, err := git.PlainOpen(repoPath) 40 if err != nil { 41 - writeError(w, xrpcerr.NewXrpcError( 42 - xrpcerr.WithTag("RepoNotFound"), 43 - xrpcerr.WithMessage("repository not found"), 44 - ), http.StatusNotFound) 45 return 46 } 47
··· 38 39 gr, err := git.PlainOpen(repoPath) 40 if err != nil { 41 + writeError(w, xrpcerr.RepoNotFoundError, http.StatusNoContent) 42 return 43 } 44
+1 -4
knotserver/xrpc/repo_tags.go
··· 33 gr, err := git.PlainOpen(repoPath) 34 if err != nil { 35 x.Logger.Error("failed to open", "error", err) 36 - writeError(w, xrpcerr.NewXrpcError( 37 - xrpcerr.WithTag("RepoNotFound"), 38 - xrpcerr.WithMessage("repository not found"), 39 - ), http.StatusNoContent) 40 return 41 } 42
··· 33 gr, err := git.PlainOpen(repoPath) 34 if err != nil { 35 x.Logger.Error("failed to open", "error", err) 36 + writeError(w, xrpcerr.RepoNotFoundError, http.StatusNoContent) 37 return 38 } 39
+2 -8
knotserver/xrpc/xrpc.go
··· 101 // Construct repository path using the same logic as didPath 102 didRepoPath, err := securejoin.SecureJoin(did, repoName) 103 if err != nil { 104 - return "", xrpcerr.NewXrpcError( 105 - xrpcerr.WithTag("RepoNotFound"), 106 - xrpcerr.WithMessage("failed to access repository"), 107 - ) 108 } 109 110 repoPath, err := securejoin.SecureJoin(x.Config.Repo.ScanPath, didRepoPath) 111 if err != nil { 112 - return "", xrpcerr.NewXrpcError( 113 - xrpcerr.WithTag("RepoNotFound"), 114 - xrpcerr.WithMessage("failed to access repository"), 115 - ) 116 } 117 118 return repoPath, nil
··· 101 // Construct repository path using the same logic as didPath 102 didRepoPath, err := securejoin.SecureJoin(did, repoName) 103 if err != nil { 104 + return "", xrpcerr.RepoNotFoundError 105 } 106 107 repoPath, err := securejoin.SecureJoin(x.Config.Repo.ScanPath, didRepoPath) 108 if err != nil { 109 + return "", xrpcerr.RepoNotFoundError 110 } 111 112 return repoPath, nil
+5
xrpc/errors/errors.go
··· 56 WithMessage("owner not set for this service"), 57 ) 58 59 var AuthError = func(err error) XrpcError { 60 return NewXrpcError( 61 WithTag("Auth"),
··· 56 WithMessage("owner not set for this service"), 57 ) 58 59 + var RepoNotFoundError = NewXrpcError( 60 + WithTag("RepoNotFound"), 61 + WithMessage("failed to access repository"), 62 + ) 63 + 64 var AuthError = func(err error) XrpcError { 65 return NewXrpcError( 66 WithTag("Auth"),