Mercurial > hg > orthanc-stone
diff Platforms/Wasm/WasmWebService.js @ 309:14ef1227120f am-callable-and-promise
web services: better handling of failures
author | am@osimis.io |
---|---|
date | Fri, 28 Sep 2018 15:02:43 +0200 |
parents | ed1a4302154f |
children | aad37d0b6407 |
line wrap: on
line diff
--- a/Platforms/Wasm/WasmWebService.js Tue Sep 25 15:14:53 2018 +0200 +++ b/Platforms/Wasm/WasmWebService.js Fri Sep 28 15:02:43 2018 +0200 @@ -1,5 +1,5 @@ mergeInto(LibraryManager.library, { - WasmWebService_GetAsync: function(callableSuccess, callableFailure, url, headersInJsonString, payload) { + WasmWebService_GetAsync: function(callableSuccess, callableFailure, url, headersInJsonString, payload, timeoutInSeconds) { // Directly use XMLHttpRequest (no jQuery) to retrieve the raw binary data // http://www.henryalgus.com/reading-binary-files-using-jquery-ajax/ var xhr = new XMLHttpRequest(); @@ -8,6 +8,7 @@ xhr.open('GET', url_, true); xhr.responseType = 'arraybuffer'; + xhr.timeout = timeoutInSeconds * 1000; var headers = JSON.parse(headersInJsonString_); for (var key in headers) { xhr.setRequestHeader(key, headers[key]); @@ -30,11 +31,12 @@ xhr.send(); }, - WasmWebService_PostAsync: function(callableSuccess, callableFailure, url, headersInJsonString, body, bodySize, payload) { + WasmWebService_PostAsync: function(callableSuccess, callableFailure, url, headersInJsonString, body, bodySize, payload, timeoutInSeconds) { var xhr = new XMLHttpRequest(); var url_ = UTF8ToString(url); var headersInJsonString_ = UTF8ToString(headersInJsonString); xhr.open('POST', url_, true); + xhr.timeout = timeoutInSeconds * 1000; xhr.responseType = 'arraybuffer'; xhr.setRequestHeader('Content-type', 'application/octet-stream');