]> gitweb.factorcode.org Git - factor.git/commitdiff
build-support/http-get.vbs: handle exceptions when making http request and writing...
authorJoe Groff <arcata@gmail.com>
Mon, 24 May 2010 22:07:23 +0000 (15:07 -0700)
committerJoe Groff <arcata@gmail.com>
Mon, 24 May 2010 22:07:23 +0000 (15:07 -0700)
build-support/http-get.vbs

index 1a279e25273f88711407a15d78fd7d2162e45704..e6e49d852b4118e9fb01abb478e6974fa9d1d34f 100644 (file)
@@ -1,3 +1,5 @@
+on error resume next\r
+\r
 if WScript.Arguments.Count < 2 then\r
     WScript.Echo "usage: http-get.vbs source-url dest-file"\r
     WScript.Quit 1\r
@@ -7,23 +9,33 @@ else
 \r
     dim http, source_data\r
     set http = CreateObject("WinHttp.WinHttpRequest.5.1")\r
+\r
+    Err.Clear\r
     http.Open "GET", source_url, false\r
     http.Send\r
 \r
-    if http.Status = 200 then\r
-        dim dest_stream\r
-        set dest_stream = CreateObject("ADODB.Stream")\r
+    if Err.Number = 0 then\r
+        if http.Status = 200 then\r
+            dim dest_stream\r
+            set dest_stream = CreateObject("ADODB.Stream")\r
 \r
-        dest_stream.Type = 1 ' adTypeBinary\r
-        dest_stream.Open\r
-        dest_stream.Write http.ResponseBody\r
-        dest_stream.SaveToFile dest_filename, 2 ' adSaveCreateOverWrite\r
-\r
-        set dest_stream = nothing\r
+            Err.Clear\r
+            dest_stream.Type = 1 ' adTypeBinary\r
+            dest_stream.Open\r
+            dest_stream.Write http.ResponseBody\r
+            dest_stream.SaveToFile dest_filename, 2 ' adSaveCreateOverWrite\r
+            if Err.Number <> 0 then\r
+                WScript.Echo "Error " + CStr(Err.Number) + " when writing " + dest_filename + ":"\r
+                WScript.Echo Err.Description\r
+                WScript.Quit 1\r
+            end if\r
+        else\r
+            WScript.Echo CStr(http.Status) + " " + http.StatusText + " when fetching " + source_url\r
+            WScript.Quit 1\r
+        end if\r
     else\r
-        WScript.Echo CStr(http.Status) + " " + http.StatusText + " when fetching " + source_url\r
+        WScript.Echo "Error " + CStr(Err.Number) + " when fetching " + source_url + ":"\r
+        WScript.Echo Err.Description\r
         WScript.Quit 1\r
     end if\r
-\r
-    set http = nothing\r
 end if\r