Skip to content

Commit

Permalink
feat: deployment history release not found err handling (#3811)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ash-exp authored and Shivam-nagar23 committed Sep 12, 2023
1 parent d81b772 commit a659dd7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
9 changes: 9 additions & 0 deletions api/helm-app/applicationClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"context"
"fmt"
"github.com/caarlos0/env"
"github.com/devtron-labs/devtron/internal/constants"
"github.com/devtron-labs/devtron/internal/util"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"go.uber.org/zap"
"google.golang.org/grpc"
Expand Down Expand Up @@ -156,6 +158,13 @@ func (impl *HelmAppClientImpl) GetDeploymentHistory(ctx context.Context, in *App
}
history, err := applicationClient.GetDeploymentHistory(ctx, in)
if err != nil {
if util.GetGRPCErrorDetailedMessage(err) == ErrReleaseNotFound {
err = &util.ApiError{
Code: constants.HelmReleaseNotFound,
InternalMessage: ErrReleaseNotFound,
UserMessage: fmt.Sprintf("no release found with release name '%s'", in.ReleaseName),
}
}
return nil, err
}
return history, nil
Expand Down
1 change: 1 addition & 0 deletions api/helm-app/bean.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const (
SOURCE_HELM_APP SourceAppType = "helm-app"
SOURCE_EXTERNAL_HELM_APP SourceAppType = "external-helm-app"
SOURCE_UNKNOWN SourceAppType = "unknown"
ErrReleaseNotFound string = "release: not found"
)

type SourceAppType string
Expand Down
1 change: 1 addition & 0 deletions internal/constants/InternalErrorCode.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ const (
UserUpdateFetchRoleFailed string = "6008"

AppDetailResourceTreeNotFound string = "7000"
HelmReleaseNotFound string = "7001"

CasbinPolicyNotCreated string = "8000"

Expand Down
10 changes: 9 additions & 1 deletion internal/util/ErrorUtil.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package util
import (
"fmt"
"github.com/go-pg/pg"
"google.golang.org/grpc/status"
)

type ApiError struct {
Expand All @@ -39,11 +40,18 @@ func (e *ApiError) ErrorfInternal(format string, a ...interface{}) error {
return &ApiError{InternalMessage: fmt.Sprintf(format, a...)}
}

//default user message will be set
// default user message will be set
func (e ApiError) ErrorfUser(format string, a ...interface{}) error {
return &ApiError{InternalMessage: fmt.Sprintf(format, a...)}
}

func IsErrNoRows(err error) bool {
return pg.ErrNoRows == err
}

func GetGRPCErrorDetailedMessage(err error) string {
if errStatus, ok := status.FromError(err); ok {
return errStatus.Message()
}
return ""
}

0 comments on commit a659dd7

Please sign in to comment.