ipfs / ipfs/js-ipfs-utils

HTTPError causes structured cloning algorithm to throw

Open
#48 2 comments 0 reactions 0 assignees View on GitHub
help wanted kind/bug P3
Dominant language
JavaScript
Stars
25
Forks
30
PR merge metrics
No merged PRs in 30d

Description

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](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/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`](https://developer.mozilla.org/en-US/docs/Web/API/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:
```js
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
}
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.