diff options
author | Hayleigh Thompson <me@hayleigh.dev> | 2023-08-23 23:13:52 +0100 |
---|---|---|
committer | Hayleigh Thompson <me@hayleigh.dev> | 2023-08-23 23:13:52 +0100 |
commit | 6d295d0bcf23bb4410d6d93435ce53f9670a1d1c (patch) | |
tree | 33ac9652ed41109d425210fabdaf638f92952f0b /compat/lustre_http/src/ffi.mjs | |
parent | c0a3607d41dd24b9ea03425892a361261893d076 (diff) | |
download | lustre-6d295d0bcf23bb4410d6d93435ce53f9670a1d1c.tar.gz lustre-6d295d0bcf23bb4410d6d93435ce53f9670a1d1c.zip |
:ambulance: Update third-party lustre_http package to new api.
Diffstat (limited to 'compat/lustre_http/src/ffi.mjs')
-rw-r--r-- | compat/lustre_http/src/ffi.mjs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/compat/lustre_http/src/ffi.mjs b/compat/lustre_http/src/ffi.mjs new file mode 100644 index 0000000..bb01b09 --- /dev/null +++ b/compat/lustre_http/src/ffi.mjs @@ -0,0 +1,16 @@ +export const do_request = (method, url, body, on_success, on_error) => { + let xhr = new XMLHttpRequest() + xhr.onerror = _evt => { + console.log("error for", method, url, ":", xhr) + on_error(888, "oops!") + } + xhr.onloadend = _evt => { + switch (xhr.status) { + case 200: + case 204: on_success(xhr.responseText); break; + default: on_error(xhr.status, xhr.responseText) + } + } + xhr.open(method, url) + xhr.send(body); +} |