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:

CORS:

Even when the status of the
XmlHttpRequestisDONE, theresponsefield can be null in some scenarii:cohttp-lwt-jsoo is not prepared for this and reads
responseTextifresponseis 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:
callAPI to return a_ Result.t Lwt.tsince it actually can fail. My preferred solution, but I don't suppose changing the API is an option.Console output examples
Connection dropped:

CORS:
