Skip to content

Commit 0b5b9ac

Browse files
committed
Improve handling of tile loading errors
1 parent 160296e commit 0b5b9ac

File tree

2 files changed

+42
-39
lines changed

2 files changed

+42
-39
lines changed

src/pyramid.js

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -494,48 +494,51 @@ function _createTileLoadFunction ({
494494
}
495495
return client.retrieveInstanceFrames(retrieveOptions).then(
496496
(rawFrames) => {
497-
try {
498-
return _decodeAndTransformFrame({
499-
frame: rawFrames[0],
500-
bitsAllocated,
501-
pixelRepresentation,
502-
columns,
503-
rows,
504-
samplesPerPixel,
505-
sopInstanceUID,
506-
metadata: pyramid.metadata,
507-
iccProfiles
508-
}).then(pixelArray => {
509-
if (pixelArray.constructor === Float64Array) {
510-
// TODO: handle Float64Array using LUT
511-
throw new Error(
512-
'Double Float Pixel Data is not (yet) supported.'
513-
)
514-
}
515-
publish(
516-
targetElement,
517-
EVENT.FRAME_LOADING_ENDED,
518-
{ pixelArray, ...frameInfo }
497+
return _decodeAndTransformFrame({
498+
frame: rawFrames[0],
499+
bitsAllocated,
500+
pixelRepresentation,
501+
columns,
502+
rows,
503+
samplesPerPixel,
504+
sopInstanceUID,
505+
metadata: pyramid.metadata,
506+
iccProfiles
507+
}).then(pixelArray => {
508+
if (pixelArray.constructor === Float64Array) {
509+
// TODO: handle Float64Array using LUT
510+
throw new Error(
511+
'Double Float Pixel Data is not (yet) supported.'
519512
)
520-
if (samplesPerPixel === 3 && bitsAllocated === 8) {
521-
// Rendering of color images requires unsigned 8-bit integers
522-
return pixelArray
523-
}
524-
// Rendering of grayscale images requires floating point values
525-
return new Float32Array(
526-
pixelArray,
527-
pixelArray.byteOffset,
528-
pixelArray.byteLength / pixelArray.BYTES_PER_ELEMENT
529-
)
530-
})
531-
} catch (error) {
532-
console.error('failed to decode frame: ', error)
533-
}
513+
}
514+
publish(
515+
targetElement,
516+
EVENT.FRAME_LOADING_ENDED,
517+
{ pixelArray, ...frameInfo }
518+
)
519+
if (samplesPerPixel === 3 && bitsAllocated === 8) {
520+
// Rendering of color images requires unsigned 8-bit integers
521+
return pixelArray
522+
}
523+
// Rendering of grayscale images requires floating point values
524+
return new Float32Array(
525+
pixelArray,
526+
pixelArray.byteOffset,
527+
pixelArray.byteLength / pixelArray.BYTES_PER_ELEMENT
528+
)
529+
})
534530
}
535531
).catch(
536532
(error) => {
537533
return Promise.reject(
538-
new Error(`Failed to load tile "${index}" at level ${z}: ${error}`)
534+
new Error(
535+
`Failed to load frames ${frameNumbers} ` +
536+
`of SOP instance "${sopInstanceUID}" ` +
537+
`for channel "${channel}" ` +
538+
`at tile position (${x + 1}, ${y + 1}) ` +
539+
`at zoom level ${z}: `,
540+
error
541+
)
539542
)
540543
}
541544
)

src/webWorker/decodeAndTransformTask.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function _handler (data, doneCallback) {
6060
)
6161
}).catch(
6262
(error) => {
63-
console.error(`failed to transform frame: ${error}`)
63+
throw new Error(`Failed to transform frame: ${error}`)
6464
}
6565
)
6666
} else {
@@ -71,7 +71,7 @@ function _handler (data, doneCallback) {
7171
}
7272
}).catch(
7373
(error) => {
74-
console.error(`failed to decode frame: ${error}`)
74+
throw new Error(`Failed to decode frame: ${error}`)
7575
}
7676
)
7777
}

0 commit comments

Comments
 (0)