Repository: fission/fission (language: go)

Issue:
Fetcher does not handle http status codes properly during function specialization
During the function specialization the _fetcher_ sidecar container does not throw an error if the received response from the _storage service_, where it tries to fetch the function archive from, has an non-successful status code (e.g. 404). Instead the _fetcher_ takes the response body anyway and places it under `/userfunc/deployarchive` as plain text which I consider undesirable.

**Some Background:**
I have replaced the built-in _storage service_ with a custom implementation which relies on proper status code handling in the _fetcher_ sidecar.


Discussion / hints:

Fix patch:
diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go
index 4e053a45a4..00ca97e602 100644
--- a/pkg/utils/utils.go
+++ b/pkg/utils/utils.go
@@ -171,6 +171,10 @@ func IsURL(str string) bool {
 	return strings.HasPrefix(str, "http://") || strings.HasPrefix(str, "https://")
 }
 
+func isHttp2xxSuccessful(status int) bool {
+	return status >= 200 && status < 300
+}
+
 func DownloadUrl(ctx context.Context, httpClient *http.Client, url string, localPath string) error {
 	resp, err := ctxhttp.Get(ctx, httpClient, url)
 	if err != nil {
@@ -178,6 +182,10 @@ func DownloadUrl(ctx context.Context, httpClient *http.Client, url string, local
 	}
 	defer resp.Body.Close()
 
+	if !isHttp2xxSuccessful(resp.StatusCode) {
+		return errors.New(resp.Status)
+	}
+
 	w, err := os.Create(localPath)
 	if err != nil {
 		return err


Test patch: