Skip to content

Commit 1438e2e

Browse files
author
Deepak Sharma
authored
fix: Handling Auth Error (#56)
1 parent 4bfa169 commit 1438e2e

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

analyses/stackanalyses/controller.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,14 @@ func (mc *Controller) validatePostResponse(apiResponse *http.Response) (*driver.
153153
log.Debug().Msgf("Executing validatePostResponse.")
154154
var body driver.PostResponseType
155155
err := json.NewDecoder(apiResponse.Body).Decode(&body)
156+
157+
// In Case of Authentication Failure, json is not return from API, Need to catch before decoding.
158+
if apiResponse.StatusCode == http.StatusForbidden {
159+
log.Debug().Msgf("Status from Server: %d", apiResponse.StatusCode)
160+
log.Error().Msgf("Stack Analyses Post Request Failed. Please check auth token and try again.")
161+
return nil, fmt.Errorf("invalid authentication token")
162+
}
163+
156164
if err != nil {
157165
return nil, err
158166
}

gomanifest/generator/deps.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,6 @@ func GetDeps(cmd GoList) (map[string]DepPackage, error) {
7676
if err := cmd.Wait(); err != nil {
7777
return nil, fmt.Errorf("%v: `go list` failed, use `go mod tidy` to known more", err)
7878
}
79-
log.Info().Msgf("Total packages: \t\t%d", len(depPackagesMap))
79+
log.Debug().Msgf("Total packages: \t\t%d", len(depPackagesMap))
8080
return depPackagesMap, nil
8181
}

gomanifest/generator/manifest.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ func BuildManifest(depPackages *map[string]DepPackage) Manifest {
139139
}
140140
}
141141
}
142-
log.Info().Msgf("Source code imports: \t%d", len(sourceImports))
143-
log.Info().Msgf("Direct dependencies: \t%d", len(manifest.Packages))
142+
log.Debug().Msgf("Source code imports: \t%d", len(sourceImports))
143+
log.Debug().Msgf("Direct dependencies: \t%d", len(manifest.Packages))
144144

145145
return manifest
146146
}

0 commit comments

Comments
 (0)