diff options
author | Igor Drozdov <idrozdov@gitlab.com> | 2022-10-25 12:36:13 +0000 |
---|---|---|
committer | Igor Drozdov <idrozdov@gitlab.com> | 2022-10-25 12:36:13 +0000 |
commit | 59acf61a9b7546e86c3319a3038bddd01cde7ab3 (patch) | |
tree | 03dbb7f286454bf259c6351f85a219a25109cc06 /internal/handler/exec.go | |
parent | b42a398c92565630b541e55c2c6c0ce47cf10b58 (diff) | |
parent | 9a58cbd85d8299c992145b8dc737522b1c19ec75 (diff) | |
download | gitlab-shell-59acf61a9b7546e86c3319a3038bddd01cde7ab3.tar.gz |
Merge branch 'gitaly-limit-error' into 'main'
Improve error message for Gitaly `LimitError`s
Closes #556
See merge request https://gitlab.com/gitlab-org/gitlab-shell/-/merge_requests/691
Merged-by: Igor Drozdov <idrozdov@gitlab.com>
Approved-by: John Cai <jcai@gitlab.com>
Approved-by: Igor Drozdov <idrozdov@gitlab.com>
Co-authored-by: Alejandro RodrÃguez <alejorro70@gmail.com>
Diffstat (limited to 'internal/handler/exec.go')
-rw-r--r-- | internal/handler/exec.go | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/internal/handler/exec.go b/internal/handler/exec.go index f2d2da8..4036286 100644 --- a/internal/handler/exec.go +++ b/internal/handler/exec.go @@ -41,6 +41,24 @@ func NewGitalyCommand(cfg *config.Config, serviceName string, response *accessve return &GitalyCommand{Config: cfg, Response: response, Command: gc} } +// processGitalyError handles errors that come back from Gitaly that may be a +// LimitError. A LimitError is returned by Gitaly when it is at its limit in +// handling requests. Since this is a known error, we should print a sensible +// error message to the end user. +func processGitalyError(statusErr error) error { + if st, ok := grpcstatus.FromError(statusErr); ok { + details := st.Details() + for _, detail := range details { + switch detail.(type) { + case *pb.LimitError: + return grpcstatus.Error(grpccodes.Unavailable, "GitLab is currently unable to handle this request due to load.") + } + } + } + + return grpcstatus.Error(grpccodes.Unavailable, "The git server, Gitaly, is not available at this time. Please contact your administrator.") +} + // RunGitalyCommand provides a bootstrap for Gitaly commands executed // through GitLab-Shell. It ensures that logging, tracing and other // common concerns are configured before executing the `handler`. @@ -61,7 +79,7 @@ func (gc *GitalyCommand) RunGitalyCommand(ctx context.Context, handler GitalyHan ctxlog.WithError(err).WithFields(log.Fields{"exit_status": exitStatus}).Error("Failed to execute Git command") if grpcstatus.Code(err) == grpccodes.Unavailable { - return grpcstatus.Error(grpccodes.Unavailable, "The git server, Gitaly, is not available at this time. Please contact your administrator.") + return processGitalyError(err) } } |