Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Add error handling for if res.arrayBuffer() throws an error after making a ky request #2842

Closed
pcowgill opened this issue Jan 13, 2020 · 5 comments
Labels
pkg:http-client Issues related only to ipfs-http-client

Comments

@pcowgill
Copy link
Contributor

This is where you might want to handle the error:

https://github.com/ipfs/js-ipfs-http-client/blob/3e5967af8e456517485c8a7536792107c0ed6e63/src/block/get.js#L21

@pcowgill
Copy link
Contributor Author

@achingbrain @hugomrdias How do you prefer to handle a case like this?

    const res = await ky.post("block/get", {
      timeout: options.timeout,
      signal: options.signal,
      headers: options.headers,
      searchParams
    });

    try {
      const data = res.arrayBuffer();
      return new Block(Buffer.from(data), cid);
    } catch (error) {
      throw new Error("Error parsing ky response");
    }

How do you prefer to handle this? Throw a custom error from scratch like is done above? Just let the original error bubble through but have it be clearer by having the arrayBuffer step on its own line? Customize the existing error's message or name and throw that?

@alanshaw
Copy link
Member

alanshaw commented Feb 4, 2020

@pcowgill why do we need additional handling here?

@pcowgill
Copy link
Contributor Author

pcowgill commented Feb 4, 2020

@alanshaw The error message that bubbles all the way up without a try/catch is a bit opaque, and stack trace line numbers aren’t always reliable in React Native, especially when networking is involved so you can’t result the Chrome debugger. A custom error message that handled the case where it was undefined would have made it simpler as a dev using this lib to immediately know what wasn’t configured properly

@alanshaw
Copy link
Member

alanshaw commented Feb 6, 2020

What is the error you're receiving?

@achingbrain achingbrain transferred this issue from ipfs-inactive/js-ipfs-http-client Mar 9, 2020
@achingbrain achingbrain added the pkg:http-client Issues related only to ipfs-http-client label Mar 9, 2020
@autonome
Copy link
Contributor

Closing as there was no response - @pcowgill Please reopen if this is still an issue!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pkg:http-client Issues related only to ipfs-http-client
Projects
None yet
Development

No branches or pull requests

4 participants