Skip to content

getJSON and friends no longer fail silently

Choose a tag to compare

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

getJSON, postJSON, putJSON and deleteJSON swallowed every failure: the .catch only wrote to the console and never called responseFunction, so the caller had no way to know a request had failed. A server that accepted the connection but never replied left the call pending indefinitely, because fetch() has no timeout of its own.

  • responseFunction is now always called. On a network failure, CORS rejection or timeout it receives {status: 0, data: null}. 0 is never a real HTTP status, so it can be used to tell a failed request apart from a 4xx/5xx reply.
  • Every request aborts after 15 seconds.
  • A malformed JSON body no longer prevents the callback: the real HTTP status is passed through with data: null.

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