Skip to content

Commit 3f928f8

Browse files
authored
fix(context): return detailed error message for ns not found (#1769)
This commit improves the error handling in case the namespace is not found. It returns more detailed message rather than just returning the error. Fixes: #1738 Signed-off-by: yati1998 <[email protected]>
1 parent c9970bd commit 3f928f8

2 files changed

Lines changed: 16 additions & 2 deletions

File tree

pkg/core/localize/locales/en/cmd/context.en.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,13 @@ Your instance might have been removed.
274274
You can update your context by creating a new instance or by using the "rhoas context set-kafka" command
275275
'''
276276

277+
[context.common.error.namespace.notFound]
278+
one='''
279+
Connector namespace in your context does not exist.
280+
Your connector namespace might have been removed.
281+
You can set a namespace in the current context by creating a new connector namespace or by using the "rhoas context set-namespace" command
282+
'''
283+
277284
[context.common.error.context.notFound]
278285
one='''
279286
context with name "{{.Name}}" does not exist

pkg/shared/contextutil/util.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ package contextutil
22

33
import (
44
"context"
5+
56
"github.com/redhat-developer/app-services-cli/pkg/core/localize"
67
"github.com/redhat-developer/app-services-cli/pkg/core/servicecontext"
78

89
"github.com/redhat-developer/app-services-cli/pkg/shared/connection"
910
"github.com/redhat-developer/app-services-cli/pkg/shared/factory"
1011
connectormgmtclient "github.com/redhat-developer/app-services-sdk-go/connectormgmt/apiv1/client"
12+
connectorerror "github.com/redhat-developer/app-services-sdk-go/connectormgmt/apiv1/error"
1113
srsmgmtv1errors "github.com/redhat-developer/app-services-sdk-go/registrymgmt/apiv1/error"
1214

1315
registrymgmtclient "github.com/redhat-developer/app-services-sdk-go/registrymgmt/apiv1/client"
@@ -187,9 +189,14 @@ func GetNamespaceForServiceConfig(currCtx *servicecontext.ServiceConfig, conn *c
187189

188190
namespace, _, err := (*conn).API().ConnectorsMgmt().ConnectorNamespacesApi.GetConnectorNamespace(f.Context, currCtx.NamespaceID).Execute()
189191
if err != nil {
190-
return nil, err
191-
}
192+
if apiErr := connectorerror.GetAPIError(err); apiErr != nil {
193+
if apiErr.GetCode() == connectorerror.ERROR_7 {
194+
return nil, f.Localizer.MustLocalizeError("context.common.error.namespace.notFound")
195+
}
192196

197+
return nil, err
198+
}
199+
}
193200
return &namespace, err
194201
}
195202

0 commit comments

Comments
 (0)