build-support/http-get.vbs: handle exceptions when making http request and writing file, set appropriate errorlevel

db4
Joe Groff 2010-05-24 15:07:23 -07:00
parent 3993dace22
commit 492e07723c
1 changed files with 24 additions and 12 deletions

View File

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