Skip to content

Commit

Permalink
update params name
Browse files Browse the repository at this point in the history
  • Loading branch information
devketanpro committed Dec 19, 2024
1 parent a24ad9e commit 529e2c9
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions assets/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,23 @@ const defaultOptions = {
redirect: 'manual',
};

interface RequestOptions {
parseJson?: boolean;
}

function options(custom: any = {}) {
return Object.assign({}, defaultOptions, custom);
}

function checkStatus(response: Response, options?: { parseJson?: boolean }): Promise<any> {
const shouldParseJson = options?.parseJson ?? true;
function checkStatus(response: Response, requestOptions: RequestOptions = {parseJson: true}): Promise<any> {
const {parseJson = true} = requestOptions;

if (response.status === 204) {
return Promise.resolve({});
}

if (response.status >= 200 && response.status < 300) {
if (!shouldParseJson) {
if (!parseJson) {
return Promise.resolve(response);
}

Expand Down Expand Up @@ -83,16 +87,16 @@ class Server {
* @return {Promise}
*/
post(
url: any,
data: any,
etag?: string,
config: { parseJson?: boolean } = {parseJson: true}
url: any,
data: any,
etag?: string,
requestOptions: RequestOptions = {parseJson: true}
) {
return fetch(url, options({
method: 'POST',
headers: getHeaders(etag),
body: data ? JSON.stringify(data) : null,
})).then((response) => checkStatus(response, config));
})).then((response) => checkStatus(response, requestOptions));
}

/**
Expand Down

0 comments on commit 529e2c9

Please sign in to comment.