mirror of
https://github.com/HeyPuter/puter.git
synced 2025-02-02 23:28:39 +08: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) {
|
async get (route) {
|
||||||
return await this.fetch({ method: 'get', route });
|
return await this.fetch({ method: 'get', route });
|
||||||
}
|
}
|
||||||
async post (route, body = {}) {
|
async post (route, body = {}, options = {}) {
|
||||||
if ( this.antiCSRF ) {
|
if ( this.antiCSRF ) {
|
||||||
body.anti_csrf = await this.antiCSRF.token();
|
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) {
|
discard (key) {
|
||||||
@ -62,6 +62,8 @@ export default def(class Collector {
|
|||||||
this.origin +maybe_slash+ options.route,
|
this.origin +maybe_slash+ options.route,
|
||||||
fetchOptions,
|
fetchOptions,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ( options.no_response ) return;
|
||||||
const asJSON = await resp.json();
|
const asJSON = await resp.json();
|
||||||
|
|
||||||
if ( options.key ) this.stored[options.key] = asJSON;
|
if ( options.key ) this.stored[options.key] = asJSON;
|
||||||
|
Loading…
Reference in New Issue
Block a user