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

I want to improve the delivery of XLSX files to support a wider range of tasks. #2212

Open
ez-kraivit opened this issue Jul 4, 2024 · 0 comments

Comments

@ez-kraivit
Copy link

I need to add a condition. Let me explain first

export const getResponseBody = async (response: Response): Promise<any> => {
    if (response.status !== 204) {
        try {
            const contentType = response.headers.get('Content-Type');
            if (contentType) {
                const jsonTypes = ['application/json', 'application/problem+json'];
                const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type));
                if (isJSON) {
                    return await response.json();
                } else if (contentType === "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") {
                    return await response.arrayBuffer();
                } else {
                    return await response.text();
                }
            }
        } catch (error) {
            console.error(error);
        }
    }
    return undefined;
};

I found that const contentType = response.headers.get('Content-Type'); in my code sends "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet". I want to modify it to have the condition:

if (contentType === "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") {
    return await response.arrayBuffer();
}

Because I need arrayBuffer(), and I've tested and found that json() or text() are insufficient conditions to support response handling adequately. Please grant me permission to make these changes in the file path core/request.ts."

If you need further adjustments or have more details to add, feel free to let me know!

export const getResponseBody = async (response: Response): Promise<any> => {
    if (response.status !== 204) {
        try {
            const contentType = response.headers.get('Content-Type');
            if (contentType) {
                if (contentType === "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"){
                    return await response.arrayBuffer()
                }
                const jsonTypes = ['application/json', 'application/problem+json']
                const isJSON = jsonTypes.some(type => contentType.toLowerCase().startsWith(type));
                if (isJSON) {
                    return await response.json();
                } else {
                    return await response.text();
                }
            }
        } catch (error) {
            console.error(error);
        }
    }
    return undefined;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant