Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Cannot download items from Agenda in json format [STTNHUB-362] #1214

Merged
merged 6 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions assets/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,28 @@ function options(custom: any = {}) {
return Object.assign({}, defaultOptions, custom);
}

function checkStatus(response: Response): Promise<any> {
function checkStatus(response: Response, rawResponse = false): Promise<any> {
if (response.status === 204) {
return Promise.resolve({});
} else if (response.status >= 200 && response.status < 300) {
}

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

const contentType = response.headers.get('Content-Type');
if (contentType && contentType.includes('application/json')) {
devketanpro marked this conversation as resolved.
Show resolved Hide resolved
return response.json();
}
return Promise.resolve(response);
} else if (response.status === 400) {
}

if (response.status === 400) {
return response.json().then((data: any) => Promise.reject({errorData: data}));
} else if (response.type === 'opaqueredirect') {
}

if (response.type === 'opaqueredirect') {
window.location.reload();
}

Expand Down Expand Up @@ -70,12 +80,12 @@ class Server {
* @param {Object} data
* @return {Promise}
*/
post(url: any, data: any, etag?: string) {
post(url: any, data: any, etag?: string, rawResponse = false) {
devketanpro marked this conversation as resolved.
Show resolved Hide resolved
return fetch(url, options({
method: 'POST',
headers: getHeaders(etag),
body: data ? JSON.stringify(data) : null,
})).then(checkStatus);
})).then((response) => checkStatus(response, rawResponse));
}

/**
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);
const response = await server.post(url, payload, undefined, true);
const blob = await response.blob();
initiateDownload(blob);
} catch (error) {
Expand Down
Loading