From 1438e2e8fad1e5cac70325254cf6d586dac814a5 Mon Sep 17 00:00:00 2001 From: Deepak Sharma Date: Tue, 27 Apr 2021 04:36:00 -0700 Subject: [PATCH] fix: Handling Auth Error (#56) --- analyses/stackanalyses/controller.go | 8 ++++++++ gomanifest/generator/deps.go | 2 +- gomanifest/generator/manifest.go | 4 ++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/analyses/stackanalyses/controller.go b/analyses/stackanalyses/controller.go index ab03c4a..d9d308c 100644 --- a/analyses/stackanalyses/controller.go +++ b/analyses/stackanalyses/controller.go @@ -153,6 +153,14 @@ func (mc *Controller) validatePostResponse(apiResponse *http.Response) (*driver. log.Debug().Msgf("Executing validatePostResponse.") var body driver.PostResponseType err := json.NewDecoder(apiResponse.Body).Decode(&body) + + // In Case of Authentication Failure, json is not return from API, Need to catch before decoding. + if apiResponse.StatusCode == http.StatusForbidden { + log.Debug().Msgf("Status from Server: %d", apiResponse.StatusCode) + log.Error().Msgf("Stack Analyses Post Request Failed. Please check auth token and try again.") + return nil, fmt.Errorf("invalid authentication token") + } + if err != nil { return nil, err } diff --git a/gomanifest/generator/deps.go b/gomanifest/generator/deps.go index 9653c18..436a666 100644 --- a/gomanifest/generator/deps.go +++ b/gomanifest/generator/deps.go @@ -76,6 +76,6 @@ func GetDeps(cmd GoList) (map[string]DepPackage, error) { if err := cmd.Wait(); err != nil { return nil, fmt.Errorf("%v: `go list` failed, use `go mod tidy` to known more", err) } - log.Info().Msgf("Total packages: \t\t%d", len(depPackagesMap)) + log.Debug().Msgf("Total packages: \t\t%d", len(depPackagesMap)) return depPackagesMap, nil } diff --git a/gomanifest/generator/manifest.go b/gomanifest/generator/manifest.go index 35ba448..f883c23 100644 --- a/gomanifest/generator/manifest.go +++ b/gomanifest/generator/manifest.go @@ -139,8 +139,8 @@ func BuildManifest(depPackages *map[string]DepPackage) Manifest { } } } - log.Info().Msgf("Source code imports: \t%d", len(sourceImports)) - log.Info().Msgf("Direct dependencies: \t%d", len(manifest.Packages)) + log.Debug().Msgf("Source code imports: \t%d", len(sourceImports)) + log.Debug().Msgf("Direct dependencies: \t%d", len(manifest.Packages)) return manifest }