Skip to content

HTTPError causes structured cloning algorithm to throw #48

@Gozala

Description

@Gozala

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

class HTTPError extends Error {
constructor (response) {
super(response.statusText)
this.name = 'HTTPError'
this.response = response
}
}

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
      }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low: Not priority right nowhelp wantedSeeking public contribution on this issuekind/bugA bug in existing code (including security flaws)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions