Browse Source

Invoke error callback if browser throws exception on download (fixes #110)

pull/124/head
Matthew Holt 11 years ago
parent
commit
8849468dee
  1. 19
      papaparse.js

19
papaparse.js

@ -453,12 +453,15 @@
} }
xhr = new XMLHttpRequest(); xhr = new XMLHttpRequest();
if (!IS_WORKER) if (!IS_WORKER)
{ {
xhr.onload = chunkLoaded; xhr.onload = chunkLoaded;
xhr.onerror = chunkError; xhr.onerror = chunkError;
} }
xhr.open("GET", url, !IS_WORKER); xhr.open("GET", url, !IS_WORKER);
if (config.step) if (config.step)
{ {
var end = start + configCopy.chunkSize - 1; // minus one because byte range is inclusive var end = start + configCopy.chunkSize - 1; // minus one because byte range is inclusive
@ -466,7 +469,14 @@
end = fileSize; end = fileSize;
xhr.setRequestHeader("Range", "bytes="+start+"-"+end); xhr.setRequestHeader("Range", "bytes="+start+"-"+end);
} }
xhr.send();
try {
xhr.send();
}
catch (err) {
chunkError(err.message);
}
if (IS_WORKER && xhr.status == 0) if (IS_WORKER && xhr.status == 0)
chunkError(); chunkError();
else else
@ -535,15 +545,16 @@
nextChunk(); nextChunk();
} }
function chunkError() function chunkError(errorMessage)
{ {
var errorText = xhr.statusText || errorMessage;
if (isFunction(config.error)) if (isFunction(config.error))
config.error(xhr.statusText); config.error(errorText);
else if (IS_WORKER && config.error) else if (IS_WORKER && config.error)
{ {
global.postMessage({ global.postMessage({
workerId: Papa.WORKER_ID, workerId: Papa.WORKER_ID,
error: xhr.statusText, error: errorText,
finished: false finished: false
}); });
} }

Loading…
Cancel
Save