diff --git a/src/lib/getImageData.js b/src/lib/getImageData.js index ce5afa4e..af3d7439 100644 --- a/src/lib/getImageData.js +++ b/src/lib/getImageData.js @@ -79,7 +79,13 @@ export default function getImageData(imageIds, displaySetInstanceUid) { }); }; - const _publishAllPixelDataInseted = () => { + const _publishPixelDataInsertedError = error => { + imageDataObject.subscriptions.onPixelDataInsertedError.forEach(callback => { + callback(error); + }); + }; + + const _publishAllPixelDataInserted = () => { imageDataObject.subscriptions.onAllPixelDataInserted.forEach(callback => { callback(); }); @@ -90,6 +96,7 @@ export default function getImageData(imageIds, displaySetInstanceUid) { // Remove all subscriptions on completion. imageDataObject.subscriptions = { onPixelDataInserted: [], + onPixelDataInsertedError: [], onAllPixelDataInserted: [], }; }; @@ -108,16 +115,21 @@ export default function getImageData(imageIds, displaySetInstanceUid) { loaded: false, subscriptions: { onPixelDataInserted: [], + onPixelDataInsertedError: [], onAllPixelDataInserted: [], }, onPixelDataInserted: callback => { imageDataObject.subscriptions.onPixelDataInserted.push(callback); }, + onPixelDataInsertedError: callback => { + imageDataObject.subscriptions.onPixelDataInsertedError.push(callback); + }, onAllPixelDataInserted: callback => { imageDataObject.subscriptions.onAllPixelDataInserted.push(callback); }, _publishPixelDataInserted, - _publishAllPixelDataInseted, + _publishAllPixelDataInserted, + _publishPixelDataInsertedError, }; imageDataCache.set(displaySetInstanceUid, imageDataObject); diff --git a/src/lib/loadImageData.js b/src/lib/loadImageData.js index 388a7d36..6e28fe4c 100644 --- a/src/lib/loadImageData.js +++ b/src/lib/loadImageData.js @@ -55,6 +55,16 @@ export default function loadImageDataProgressively(imageDataObject) { const reRenderFraction = numberOfFrames / 5; let reRenderTarget = reRenderFraction; + const insertPixelDataErrorHandler = error => { + numberProcessed++; + imageDataObject._publishPixelDataInsertedError(error); + + if (numberProcessed === numberOfFrames) { + // Done loading, publish complete and remove all subscriptions. + imageDataObject._publishAllPixelDataInserted(); + } + }; + const insertPixelData = image => { const { imagePositionPatient } = metaDataMap.get(image.imageId); @@ -93,19 +103,21 @@ export default function loadImageDataProgressively(imageDataObject) { if (numberProcessed === numberOfFrames) { // Done loading, publish complete and remove all subscriptions. - imageDataObject._publishAllPixelDataInseted(); + imageDataObject._publishAllPixelDataInserted(); } }; - prefetchImageIds(imageIds, imageDataObject, insertPixelData); + prefetchImageIds(imageIds, insertPixelData, insertPixelDataErrorHandler); } const requestType = 'prefetch'; const preventCache = false; -function prefetchImageIds(imageIds, imageDataObject, insertPixelData) { - const noop = () => {}; - +function prefetchImageIds( + imageIds, + insertPixelData, + insertPixelDataErrorHandler +) { imageIds.forEach(imageId => { requestPoolManager.addRequest( {}, @@ -113,7 +125,7 @@ function prefetchImageIds(imageIds, imageDataObject, insertPixelData) { requestType, preventCache, insertPixelData, - noop + insertPixelDataErrorHandler ); });