Skip to content

response.ok = false for opaque responses may be misleading #299

@liabru

Description

@liabru

When making a cross-domain fetch one may receive a response with response.type === 'opaque'.
Currently this seems to mean (at least in Chrome) that response.ok is false even if the response succeeded.

The current spec does not appear to specify what the value for response.ok should be in this situation (see the spec here), while it does specify other values like response.status being 0). The docs on MDN also do not discuss the value in opaque cases (or that they are even a possibility).

I feel that a response.ok value of false is misleading and may catch other people out who are not aware of the meaning of opaque responses. As for what the value should be, I'm not sure. A value of true may also be equally misleading. A value of null might be better, but still has potential for issues for people naively checking for ok like most examples do.

For those just looking for a code solution, here is one way to catch this case:

  if (response.type === 'opaque' || response.ok) {
    return response;
  } else {
    // do something else
  }

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions