Skip to content

TypeError: body used already for - should be able to extract twiceΒ #533

@theogravity

Description

@theogravity

I unfortunately am calling a service which may or may not return JSON (or any) body data.

When I do the following, I get the TypeError: body used already for error:

let data = null

try {
  data = await res.json()
} catch (e) {
  data = await res.text()
}

Two things:

  • I should be able to call .json() / .text() multiple times
  • If the body is empty, it should just return null instead of throwing on .text()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions