Fix go gas issue for chartserver (#5522)

Add the error handling to fix go gas issue "Error unhandled"
This commit is contained in:
Yan 2018-08-03 19:25:39 +08:00 committed by GitHub
parent 0f519c9dc9
commit 6ed80a370d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 3 deletions

View File

@ -154,7 +154,12 @@ func getTheTwoCharts(chartVersions helm_repo.ChartVersions) (latestChart *helm_r
if latestChart == nil {
latestChart = chartVersion
} else {
lVersion, _ := semver.NewVersion(latestChart.Version)
lVersion, err := semver.NewVersion(latestChart.Version)
if err != nil {
//ignore it, just logged
hlog.Warningf("Malformed semversion %s for the chart %s", latestChart.Version, chartVersion.Name)
continue
}
if lVersion.LessThan(currentV) {
latestChart = chartVersion
}

View File

@ -18,8 +18,10 @@ const (
func WriteError(w http.ResponseWriter, code int, err error) {
errorObj := make(map[string]string)
errorObj["error"] = err.Error()
errorContent, _ := json.Marshal(errorObj)
errorContent, errorMarshal := json.Marshal(errorObj)
if errorMarshal != nil {
errorContent = []byte(err.Error())
}
w.WriteHeader(code)
w.Write(errorContent)
}