dev: support no-response endpoints in Collector

The no_response option is added to Collector::post. If an endpoint
returns an empty response, this option must be set to avoid a JSON parse
error.
This commit is contained in:
KernelDeimos 2024-10-30 18:51:27 -04:00
parent 96b64f6b53
commit 9a0c5b4f74

View File

@ -29,11 +29,11 @@ export default def(class Collector {
async get (route) {
return await this.fetch({ method: 'get', route });
}
async post (route, body = {}) {
async post (route, body = {}, options = {}) {
if ( this.antiCSRF ) {
body.anti_csrf = await this.antiCSRF.token();
}
return await this.fetch({ method: 'post', route, body });
return await this.fetch({ ...options, method: 'post', route, body });
}
discard (key) {
@ -62,6 +62,8 @@ export default def(class Collector {
this.origin +maybe_slash+ options.route,
fetchOptions,
);
if ( options.no_response ) return;
const asJSON = await resp.json();
if ( options.key ) this.stored[options.key] = asJSON;