mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-25 09:38:06 +02:00
Handle JPX wasm fetch-response errors correctly (PR 19329 follow-up)
Currently we're not checking that the response is actually OK before getting the data, which means that rather than throwing an error we can get an empty `ArrayBuffer`. To avoid duplicating code we can move an existing helper into `src/core/core_utils.js` and re-use it when fetching the JPX wasm-file as well.
This commit is contained in:
parent
88735d0f14
commit
6038b5a992
3 changed files with 24 additions and 17 deletions
|
@ -103,6 +103,16 @@ function arrayBuffersToBytes(arr) {
|
|||
return data;
|
||||
}
|
||||
|
||||
async function fetchBinaryData(url) {
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
throw new Error(
|
||||
`Failed to fetch file "${url}" with "${response.statusText}".`
|
||||
);
|
||||
}
|
||||
return new Uint8Array(await response.arrayBuffer());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of an inheritable property.
|
||||
*
|
||||
|
@ -701,6 +711,7 @@ export {
|
|||
encodeToXmlString,
|
||||
escapePDFName,
|
||||
escapeString,
|
||||
fetchBinaryData,
|
||||
getInheritableProperty,
|
||||
getLookupTableFactory,
|
||||
getNewAnnotationsMap,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue