js-ipfs-utils icon indicating copy to clipboard operation
js-ipfs-utils copied to clipboard

HTTPError causes structured cloning algorithm to throw

Open Gozala opened this issue 4 years ago • 2 comments

I have quite a bit time figuring out why some of the tests were failing (in https://github.com/ipfs/js-ipfs/pull/3081) on Firefox. Turns out structured clone algorithm throws when HTTError is being posted over message channel

https://github.com/ipfs/js-ipfs-utils/blob/4cc38261601c7be6c8f84f63f2b2324608f0063b/src/http.js#L21-L27

There are multiple issues:

  1. Firefox does not yet support native Error types https://bugzilla.mozilla.org/show_bug.cgi?id=1556604
  2. Even with the above resolved response: Response still creates an issue.

I'm not sure what the appropriate course of action would be here, but here are few options:

  1. Making response non-enumerable property, which would be ignored.
  2. Instead of attaching Response instance extend HTTPError to include relevant data e.g:
    class HTTPError extends Error {
      constructor (response) {
        super(response.statusText)
        this.name = 'HTTPError'
        this.statusText = response.statusText
        this.responseType = response.type
        this.url = response.url
        this.status = response.status
        this.redirected = response.redirected
      }
    }
    

Gozala avatar Jun 19 '20 20:06 Gozala

Thank you for submitting your first issue to this repository! A maintainer will be here shortly to triage and review. In the meantime, please double-check that you have provided all the necessary information to make this process easy! Any information that can help save additional round trips is useful! We currently aim to give initial feedback within two business days. If this does not happen, feel free to leave a comment. Please keep an eye on how this issue will be labeled, as labels give an overview of priorities, assignments and additional actions requested by the maintainers:

  • "Priority" labels will show how urgent this is for the team.
  • "Status" labels will show if this is ready to be worked on, blocked, or in progress.
  • "Need" labels will indicate if additional input or analysis is required.

Finally, remember to use https://discuss.ipfs.io if you just need general support.

welcome[bot] avatar Jun 19 '20 20:06 welcome[bot]

Perhaps option 2? Could you take a look at the code and see if we even use the response anywhere an if so, which properties we use?

achingbrain avatar Jul 09 '20 14:07 achingbrain