forked from tangled.org/core
Monorepo for Tangled

xrpc,knotserver: refactor RefNotFound errors

Signed-off-by: oppiliappan <me@oppi.li>

authored by oppi.li and committed by Tangled 96159595 d5f4fd4d

+1 -4
knotserver/xrpc/repo_archive.go
··· 40 40 41 41 gr, err := git.Open(repoPath, ref) 42 42 if err != nil { 43 - writeError(w, xrpcerr.NewXrpcError( 44 - xrpcerr.WithTag("RefNotFound"), 45 - xrpcerr.WithMessage("repository or ref not found"), 46 - ), http.StatusNotFound) 43 + writeError(w, xrpcerr.RefNotFoundError, http.StatusNotFound) 47 44 return 48 45 } 49 46
+1 -4
knotserver/xrpc/repo_blob.go
··· 39 39 40 40 gr, err := git.Open(repoPath, ref) 41 41 if err != nil { 42 - writeError(w, xrpcerr.NewXrpcError( 43 - xrpcerr.WithTag("RefNotFound"), 44 - xrpcerr.WithMessage("repository or ref not found"), 45 - ), http.StatusNotFound) 42 + writeError(w, xrpcerr.RefNotFoundError, http.StatusNotFound) 46 43 return 47 44 } 48 45
+2 -8
knotserver/xrpc/repo_diff.go
··· 22 22 23 23 gr, err := git.Open(repoPath, ref) 24 24 if err != nil { 25 - writeError(w, xrpcerr.NewXrpcError( 26 - xrpcerr.WithTag("RefNotFound"), 27 - xrpcerr.WithMessage("repository or ref not found"), 28 - ), http.StatusNotFound) 25 + writeError(w, xrpcerr.RefNotFoundError, http.StatusNotFound) 29 26 return 30 27 } 31 28 32 29 diff, err := gr.Diff() 33 30 if err != nil { 34 31 x.Logger.Error("getting diff", "error", err.Error()) 35 - writeError(w, xrpcerr.NewXrpcError( 36 - xrpcerr.WithTag("RefNotFound"), 37 - xrpcerr.WithMessage("failed to generate diff"), 38 - ), http.StatusInternalServerError) 32 + writeError(w, xrpcerr.RefNotFoundError, http.StatusInternalServerError) 39 33 return 40 34 } 41 35
+1 -4
knotserver/xrpc/repo_languages.go
··· 25 25 gr, err := git.Open(repoPath, ref) 26 26 if err != nil { 27 27 x.Logger.Error("opening repo", "error", err.Error()) 28 - writeError(w, xrpcerr.NewXrpcError( 29 - xrpcerr.WithTag("RefNotFound"), 30 - xrpcerr.WithMessage("repository or ref not found"), 31 - ), http.StatusNotFound) 28 + writeError(w, xrpcerr.RefNotFoundError, http.StatusNotFound) 32 29 return 33 30 } 34 31
+1 -4
knotserver/xrpc/repo_log.go
··· 32 32 33 33 gr, err := git.Open(repoPath, ref) 34 34 if err != nil { 35 - writeError(w, xrpcerr.NewXrpcError( 36 - xrpcerr.WithTag("RefNotFound"), 37 - xrpcerr.WithMessage("repository or ref not found"), 38 - ), http.StatusNotFound) 35 + writeError(w, xrpcerr.RefNotFoundError, http.StatusNotFound) 39 36 return 40 37 } 41 38
+1 -4
knotserver/xrpc/repo_tree.go
··· 30 30 gr, err := git.Open(repoPath, ref) 31 31 if err != nil { 32 32 x.Logger.Error("failed to open git repository", "error", err, "path", repoPath, "ref", ref) 33 - writeError(w, xrpcerr.NewXrpcError( 34 - xrpcerr.WithTag("RefNotFound"), 35 - xrpcerr.WithMessage("repository or ref not found"), 36 - ), http.StatusNotFound) 33 + writeError(w, xrpcerr.RefNotFoundError, http.StatusNotFound) 37 34 return 38 35 } 39 36
+5
xrpc/errors/errors.go
··· 61 61 WithMessage("failed to access repository"), 62 62 ) 63 63 64 + var RefNotFoundError = NewXrpcError( 65 + WithTag("RefNotFound"), 66 + WithMessage("failed to access ref"), 67 + ) 68 + 64 69 var AuthError = func(err error) XrpcError { 65 70 return NewXrpcError( 66 71 WithTag("Auth"),