diff --git a/plugins/http/guest-js/index.ts b/plugins/http/guest-js/index.ts index 9c88e2808..b76db724a 100644 --- a/plugins/http/guest-js/index.ts +++ b/plugins/http/guest-js/index.ts @@ -33,45 +33,50 @@ declare global { async function readBody(rid: number, kind: "blob" | "text"): Promise { return await window.__TAURI_INVOKE__("plugin:http|fetch_read_body", { rid, - kind + kind, }); } class TauriResponse extends Response { - _rid: number = 0 + _rid: number = 0; blob(): Promise { - return readBody(this._rid, "blob").then(bytes => new Blob([bytes], { type: this.headers.get("content-type") || "application/octet-stream" })) + return readBody(this._rid, "blob").then( + (bytes) => + new Blob([bytes], { + type: this.headers.get("content-type") || "application/octet-stream", + }), + ); } - json(): Promise { - return readBody(this._rid, "text").then(data => { + json(): Promise { + return readBody(this._rid, "text").then((data) => { try { return JSON.parse(data); } catch (e) { if (this.ok && data === "") { return {}; } else if (this.ok) { - throw Error( - `Failed to parse response \`${data}\` as JSON: ${e}` - ); + throw Error(`Failed to parse response \`${data}\` as JSON: ${e}`); } } - }) + }); } formData(): Promise { - return this.json().then((json: Record) => { - const form = new FormData() - for (const [key, value] of Object.entries(json)) { - form.append(key, value) + return this.json().then((json) => { + const form = new FormData(); + for (const [key, value] of Object.entries( + json as Record, + )) { + form.append(key, value); } - return form - }) + return form; + }); } text(): Promise { - return readBody(this._rid, "text") + return readBody(this._rid, "text"); } } @@ -106,7 +111,7 @@ export interface ClientOptions { */ export async function fetch( input: URL | Request | string, - init?: RequestInit & ClientOptions + init?: RequestInit & ClientOptions, ): Promise { const maxRedirections = init?.maxRedirections; const connectTimeout = init?.maxRedirections;