From ac4ba84112f772ebbaab03e44d78a7a328a07291 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20W=C3=A5reus?= Date: Thu, 23 Nov 2023 16:07:23 +0100 Subject: [PATCH] add error message to forbidden status code in cli --- internal/client/request.go | 14 ++++++++++++++ internal/upload/batch.go | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/internal/client/request.go b/internal/client/request.go index c799215b..463cac80 100644 --- a/internal/client/request.go +++ b/internal/client/request.go @@ -85,6 +85,20 @@ func newRequest(method string, url string, jwtToken string, format string, body func interpret(res *http.Response, request func() (*http.Response, error), debClient *DebClient, retry bool) (*http.Response, error) { if res == nil { return nil, NoResErr + } else if res.StatusCode == http.StatusForbidden { + errMsg := `Unauthorized. You don't have the necessary access to perform this action. +Contact your debricked company admin or repository admin to request proper access. +For enterprise user: https://portal.debricked.com/administration-47/how-do-i-generate-an-access-token-130` + if retry { + err := debClient.authenticate() + if err != nil { + return nil, errors.New(errMsg) + } + + return request() + } + return nil, errors.New(errMsg) + } else if res.StatusCode == http.StatusUnauthorized { errMsg := `Unauthorized. Specify access token. Read more on https://portal.debricked.com/administration-47/how-do-i-generate-an-access-token-130` diff --git a/internal/upload/batch.go b/internal/upload/batch.go index cbbe9c33..2663e47b 100644 --- a/internal/upload/batch.go +++ b/internal/upload/batch.go @@ -256,7 +256,7 @@ func (uploadBatch *uploadBatch) initUpload() ([]string, error) { } } - errStr := fmt.Sprintf("failed to initialize a scan due to badly formatted files, initial upload file %s got the following error: %s", entryFile, err.Error()) + errStr := fmt.Sprintf("Failed to initialize a scan for %s. Got the following error: %s", entryFile, err.Error()) return files, errors.New(errStr) }