Skip to content

Commit d025262

Browse files
authored
fix: 🐛 Handle failed loads when fetching data (#107)
1 parent 3ec7c89 commit d025262

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

src/lib/getImageData.js

+14-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,13 @@ export default function getImageData(imageIds, displaySetInstanceUid) {
7979
});
8080
};
8181

82-
const _publishAllPixelDataInseted = () => {
82+
const _publishPixelDataInsertedError = error => {
83+
imageDataObject.subscriptions.onPixelDataInsertedError.forEach(callback => {
84+
callback(error);
85+
});
86+
};
87+
88+
const _publishAllPixelDataInserted = () => {
8389
imageDataObject.subscriptions.onAllPixelDataInserted.forEach(callback => {
8490
callback();
8591
});
@@ -90,6 +96,7 @@ export default function getImageData(imageIds, displaySetInstanceUid) {
9096
// Remove all subscriptions on completion.
9197
imageDataObject.subscriptions = {
9298
onPixelDataInserted: [],
99+
onPixelDataInsertedError: [],
93100
onAllPixelDataInserted: [],
94101
};
95102
};
@@ -108,16 +115,21 @@ export default function getImageData(imageIds, displaySetInstanceUid) {
108115
loaded: false,
109116
subscriptions: {
110117
onPixelDataInserted: [],
118+
onPixelDataInsertedError: [],
111119
onAllPixelDataInserted: [],
112120
},
113121
onPixelDataInserted: callback => {
114122
imageDataObject.subscriptions.onPixelDataInserted.push(callback);
115123
},
124+
onPixelDataInsertedError: callback => {
125+
imageDataObject.subscriptions.onPixelDataInsertedError.push(callback);
126+
},
116127
onAllPixelDataInserted: callback => {
117128
imageDataObject.subscriptions.onAllPixelDataInserted.push(callback);
118129
},
119130
_publishPixelDataInserted,
120-
_publishAllPixelDataInseted,
131+
_publishAllPixelDataInserted,
132+
_publishPixelDataInsertedError,
121133
};
122134

123135
imageDataCache.set(displaySetInstanceUid, imageDataObject);

src/lib/loadImageData.js

+18-6
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ export default function loadImageDataProgressively(imageDataObject) {
5555
const reRenderFraction = numberOfFrames / 5;
5656
let reRenderTarget = reRenderFraction;
5757

58+
const insertPixelDataErrorHandler = error => {
59+
numberProcessed++;
60+
imageDataObject._publishPixelDataInsertedError(error);
61+
62+
if (numberProcessed === numberOfFrames) {
63+
// Done loading, publish complete and remove all subscriptions.
64+
imageDataObject._publishAllPixelDataInserted();
65+
}
66+
};
67+
5868
const insertPixelData = image => {
5969
const { imagePositionPatient } = metaDataMap.get(image.imageId);
6070

@@ -93,27 +103,29 @@ export default function loadImageDataProgressively(imageDataObject) {
93103

94104
if (numberProcessed === numberOfFrames) {
95105
// Done loading, publish complete and remove all subscriptions.
96-
imageDataObject._publishAllPixelDataInseted();
106+
imageDataObject._publishAllPixelDataInserted();
97107
}
98108
};
99109

100-
prefetchImageIds(imageIds, imageDataObject, insertPixelData);
110+
prefetchImageIds(imageIds, insertPixelData, insertPixelDataErrorHandler);
101111
}
102112

103113
const requestType = 'prefetch';
104114
const preventCache = false;
105115

106-
function prefetchImageIds(imageIds, imageDataObject, insertPixelData) {
107-
const noop = () => {};
108-
116+
function prefetchImageIds(
117+
imageIds,
118+
insertPixelData,
119+
insertPixelDataErrorHandler
120+
) {
109121
imageIds.forEach(imageId => {
110122
requestPoolManager.addRequest(
111123
{},
112124
imageId,
113125
requestType,
114126
preventCache,
115127
insertPixelData,
116-
noop
128+
insertPixelDataErrorHandler
117129
);
118130
});
119131

0 commit comments

Comments
 (0)