Skip to content

Commit

Permalink
update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
devketanpro committed Dec 19, 2024
1 parent 5171c7a commit a24ad9e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions assets/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ function options(custom: any = {}) {
return Object.assign({}, defaultOptions, custom);
}

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

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

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

Expand Down Expand Up @@ -80,12 +82,17 @@ class Server {
* @param {Object} data
* @return {Promise}
*/
post(url: any, data: any, etag?: string, rawResponse = false) {
post(
url: any,
data: any,
etag?: string,
config: { parseJson?: boolean } = {parseJson: true}
) {
return fetch(url, options({
method: 'POST',
headers: getHeaders(etag),
body: data ? JSON.stringify(data) : null,
})).then((response) => checkStatus(response, rawResponse));
})).then((response) => checkStatus(response, config));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion assets/wire/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ export function submitDownloadItems(items: any, params: any) {
}
else{
try {
const response = await server.post(url, payload, undefined, true);
const response = await server.post(url, payload, undefined, {parseJson: false});
const blob = await response.blob();
initiateDownload(blob);
} catch (error) {
Expand Down

0 comments on commit a24ad9e

Please sign in to comment.