Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix - File fetching broken since commit 0c1d2b9 #1375

Merged
merged 11 commits into from
Aug 28, 2023

Conversation

mercpls
Copy link

@mercpls mercpls commented Aug 10, 2023

#1371
As noted in 1371, and other discussion outside of whatwg/fetch, it's been found that adding the RangeError for statuses outside of 200-599 causes local File fetches to fail.

i.e.
fetch("file://some/local/path")

This PR adds a simple check for the file path before returning the response, it could alternatively be added to the 200/599 status check as a not condition.

Not sure if this has the potential to break other things, or if there's a better way to handle the RangeError issue with file:// not setting a status.

Thanks

@mercpls mercpls changed the title (Fix) - File fetching broken since commit 0c1d2b9 (WIP) - File fetching broken since commit 0c1d2b9 Aug 11, 2023
@mercpls mercpls changed the title (WIP) - File fetching broken since commit 0c1d2b9 Fix - File fetching broken since commit 0c1d2b9 Aug 11, 2023
@ghost
Copy link

ghost commented Aug 18, 2023

Confirm, RangeError is freaking me out after I've upgraded to expo@49
Error output:

ERROR  RangeError: Failed to construct 'Response': The status provided (0) is outside the range [200, 599]., js engine: hermes

Code that causes this error:

await (await fetch(fileUrl)).blob())

@mercpls
Copy link
Author

mercpls commented Aug 18, 2023

Confirm, RangeError is freaking me out after I've upgraded to expo@49 Error output:

ERROR  RangeError: Failed to construct 'Response': The status provided (0) is outside the range [200, 599]., js engine: hermes

Code that causes this error:

await (await fetch(fileUrl)).blob())

@bogdanbpeterson A temporary fix is to create your own XMLHttpRequest, just like this library does, except you would handle the errors on your own so that this issue doesn't happen.

You can also rollback to the commit of the whatwg/fetch version before the RangeError was introduced.

const uriToBlob = (uri: string): Promise<Blob> => {
  return new Promise((resolve, reject) => {
    const xhr = new XMLHttpRequest();
    xhr.onload = () => resolve(xhr.response);
    xhr.onerror = () => reject(new Error('uriToBlob failed'));
    xhr.responseType = 'blob';
    xhr.open('GET', uri, true);
    xhr.send(null);
  });
};

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants