Skip to content

Failure handling for the remaining api.js and element.js requests

Choose a tag to compare

@awangga awangga released this 11 Sep 22:15
· 79 commits to main since this release

v0.0.9 only covered the four JSON functions. Every other network call in the library had the same problem.

  • postFile, postFileWithHeader, postFileJSON: a network failure was only logged, and JSON.parse threw on a non-JSON reply. Either way the callback never fired. They now call back with null, or {status: 0, data: null} for postFileJSON.
  • getFileBytesWithHeader: on a 200 reply it read response.arrayBuffer() and then discarded it, so the function never delivered file bytes to anyone. It now passes the ArrayBuffer to the callback.
  • getFileWithHeader and getFileBytesWithHeader: a non-JSON error body previously stopped the callback from firing; network failures now call back with {status: 0}.
  • insertHTML: the error message blamed a missing element for every failure, including network errors. The element is now checked before the request.
  • Added the 15 second timeout to every request in api.js, and to renderHTML/replaceTag in element.js.

Docs: https://croot.js.org/docs/api/