Skip to content

Jsoo implementation fails when the xhr.response field is null. #737

@mefyl

Description

@mefyl

Even when the status of the XmlHttpRequest is DONE, the response field can be null in some scenarii:

  • The request failed CORS. The browser will not let you access the response content for security reasons.
  • The request was aborted because of a disconnection (on Chrome / v8 at least).

cohttp-lwt-jsoo is not prepared for this and reads responseText if response is not an arraybuffer, raising an exception from the onreadystagechange callback which is thus not catchable by the caml caller and escapes directly to the javascript toplevel (see attached console logs).

I can easily submit a fix for this, but would like to inquire about the preferred approach API-wise:

  • Change the call API to return a _ Result.t Lwt.t since it actually can fail. My preferred solution, but I don't suppose changing the API is an option.
  • Forward the javascript exception to the caller unwrapped whatsoever, so she can at least catch it.
  • Wrap the exception in a neat Ocaml exception.

Console output examples

Connection dropped:
image

CORS:
image

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