Skip to content

Commit 75e9764

Browse files
committed
simplify project-not-found error warning
1 parent 1cdfb3e commit 75e9764

File tree

2 files changed

+2
-23
lines changed

2 files changed

+2
-23
lines changed

internal/pkg/errors/errors.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,7 @@ To list all profiles, run:
179179

180180
FILE_ALREADY_EXISTS = `file %q already exists in the export path. Delete the existing file or define a different export path`
181181

182-
PROJECT_NOT_FOUND = `the project %[2]q (ID: %[1]s) does not exist.
183-
184-
To list all available projects, run:
185-
$ stackit project list`
186-
187-
PROJECT_ACCESS_DENIED = `you don't have access to the project %[2]q (ID: %[1]s).
182+
PROJECT_NOT_FOUND = `the project %[2]q (ID: %[1]s) does not exist or you don't have access to it.
188183
189184
To list all available projects, run:
190185
$ stackit project list`
@@ -518,12 +513,3 @@ type ProjectNotFoundError struct {
518513
func (e *ProjectNotFoundError) Error() string {
519514
return fmt.Sprintf(PROJECT_NOT_FOUND, e.ProjectId, e.ProjectLabel)
520515
}
521-
522-
type ProjectAccessDeniedError struct {
523-
ProjectId string
524-
ProjectLabel string
525-
}
526-
527-
func (e *ProjectAccessDeniedError) Error() string {
528-
return fmt.Sprintf(PROJECT_ACCESS_DENIED, e.ProjectId, e.ProjectLabel)
529-
}

internal/pkg/validation/project.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,13 @@ func ValidateProject(ctx context.Context, p *print.Printer, cliVersion string, c
3535
// Check for specific HTTP status codes
3636
if httpErr, ok := err.(*oapierror.GenericOpenAPIError); ok { //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
3737
switch httpErr.StatusCode {
38-
case http.StatusNotFound:
38+
case http.StatusNotFound, http.StatusForbidden:
3939
// Try to get project name for better error message
4040
projectLabel := projectId
4141
if projectName, nameErr := projectname.GetProjectName(ctx, p, cliVersion, cmd); nameErr == nil {
4242
projectLabel = projectName
4343
}
4444
return "", &errors.ProjectNotFoundError{ProjectId: projectId, ProjectLabel: projectLabel}
45-
case http.StatusForbidden:
46-
// Try to get project name for better error message
47-
projectLabel := projectId
48-
if projectName, nameErr := projectname.GetProjectName(ctx, p, cliVersion, cmd); nameErr == nil {
49-
projectLabel = projectName
50-
}
51-
return "", &errors.ProjectAccessDeniedError{ProjectId: projectId, ProjectLabel: projectLabel}
5245
case http.StatusUnauthorized:
5346
return "", &errors.AuthError{}
5447
}

0 commit comments

Comments
 (0)