mirror of
https://github.com/HeyPuter/puter
synced 2024-11-14 22:06:00 +00:00
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:
parent
96b64f6b53
commit
9a0c5b4f74
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user