Fix ignoring error (#1356)

* fix ignoring error

* fix operator

* fix minio error handling

* fix get url to return error if failed parsing

* add error handling

* position of statement to get redirect url was wrong.
This commit is contained in:
Kenshi Kamata
2019-09-17 06:15:51 +09:00
committed by Aaron Schlesinger
parent 1eef6b9940
commit 800024fc6f
6 changed files with 38 additions and 7 deletions
+6 -3
View File
@@ -55,8 +55,11 @@ func RegisterHandlers(r *mux.Router, opts *HandlerOpts) {
r.Handle(PathVersionZip, LogEntryHandler(ZipHandler, opts)).Methods(http.MethodGet)
}
func getRedirectURL(base, path string) string {
url, _ := url.Parse(base)
func getRedirectURL(base, path string) (string, error) {
url, err := url.Parse(base)
if err != nil {
return "", err
}
url.Path = path
return url.String()
return url.String(), nil
}
+7 -1
View File
@@ -26,7 +26,13 @@ func InfoHandler(dp Protocol, lggr log.Entry, df *mode.DownloadFile) http.Handle
severityLevel := errors.Expect(err, errors.KindNotFound, errors.KindRedirect)
lggr.SystemErr(errors.E(op, err, errors.M(mod), errors.V(ver), severityLevel))
if errors.Kind(err) == errors.KindRedirect {
http.Redirect(w, r, getRedirectURL(df.URL(mod), r.URL.Path), errors.KindRedirect)
url, err := getRedirectURL(df.URL(mod), r.URL.Path)
if err != nil {
lggr.SystemErr(err)
w.WriteHeader(errors.Kind(err))
return
}
http.Redirect(w, r, url, errors.KindRedirect)
return
}
w.WriteHeader(errors.Kind(err))
+8 -1
View File
@@ -28,7 +28,14 @@ func ModuleHandler(dp Protocol, lggr log.Entry, df *mode.DownloadFile) http.Hand
err = errors.E(op, err, severityLevel)
lggr.SystemErr(err)
if errors.Kind(err) == errors.KindRedirect {
http.Redirect(w, r, getRedirectURL(df.URL(mod), r.URL.Path), errors.KindRedirect)
url, err := getRedirectURL(df.URL(mod), r.URL.Path)
if err != nil {
err = errors.E(op, errors.M(mod), errors.V(ver), err)
lggr.SystemErr(err)
w.WriteHeader(errors.Kind(err))
return
}
http.Redirect(w, r, url, errors.KindRedirect)
return
}
w.WriteHeader(errors.Kind(err))
+7 -1
View File
@@ -28,7 +28,13 @@ func ZipHandler(dp Protocol, lggr log.Entry, df *mode.DownloadFile) http.Handler
err = errors.E(op, err, severityLevel)
lggr.SystemErr(err)
if errors.Kind(err) == errors.KindRedirect {
http.Redirect(w, r, getRedirectURL(df.URL(mod), r.URL.Path), errors.KindRedirect)
url, err := getRedirectURL(df.URL(mod), r.URL.Path)
if err != nil {
lggr.SystemErr(err)
w.WriteHeader(errors.Kind(err))
return
}
http.Redirect(w, r, url, errors.KindRedirect)
return
}
w.WriteHeader(errors.Kind(err))