Skip to content

Commit

Permalink
fix(loaders): properly catches render errors and calls onError callback
Browse files Browse the repository at this point in the history
related issue: #16

the problem is caused by the fact that an empty string or any other "real-file-but-not-an-image" (an empty string is a request to load index.html basically) gets fulfilled by the server with a 200 OK status, returned by FileLoader -> we get the HTML in return (which is not an image) and then we try to render it anyway.

this catches errors in the LoaderBase render function and properly calls the onError callback
  • Loading branch information
daniele-pelagatti committed Nov 29, 2023
1 parent 43cab7a commit b9bcdd1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/decode/loaders/GainMapLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,17 @@ export class GainMapLoader extends LoaderBase<[string, string, string]> {

const loadCheck = async () => {
if (sdr && gainMap && metadata) {
await this.render(quadRenderer, metadata, sdr, gainMap)
// solves #16
try {
await this.render(quadRenderer, metadata, sdr, gainMap)
} catch (error) {
this.manager.itemError(sdrUrl)
this.manager.itemError(gainMapUrl)
this.manager.itemError(metadataUrl)
if (typeof onError === 'function') onError(error)
quadRenderer.disposeOnDemandRenderer()
return
}

if (typeof onLoad === 'function') onLoad(quadRenderer)
this.manager.itemEnd(sdrUrl)
Expand Down
11 changes: 10 additions & 1 deletion src/decode/loaders/HDRJPGLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,16 @@ export class HDRJPGLoader extends LoaderBase<string> {
throw e
}
}
await this.render(quadRenderer, metadata, sdrJPEG, gainMapJPEG)

// solves #16
try {
await this.render(quadRenderer, metadata, sdrJPEG, gainMapJPEG)
} catch (error) {
this.manager.itemError(url)
if (typeof onError === 'function') onError(error)
quadRenderer.disposeOnDemandRenderer()
return
}

if (typeof onLoad === 'function') onLoad(quadRenderer)
this.manager.itemEnd(url)
Expand Down

0 comments on commit b9bcdd1

Please sign in to comment.