Skip to content

Commit

Permalink
add error message to forbidden status code in cli
Browse files Browse the repository at this point in the history
  • Loading branch information
emilwareus committed Nov 23, 2023
1 parent c61a9a5 commit ac4ba84
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions internal/client/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 1 addition & 1 deletion internal/upload/batch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit ac4ba84

Please sign in to comment.