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

bugfix/improper-status-code #588

Merged
merged 4 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion lib/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export async function newPage(poolResource) {

// Throw an error in case of no connected browser
if (!browser || !browser.connected) {
throw new ExportError(`[browser] Browser is not yet connected.`, 400);
throw new ExportError(`[browser] Browser is not yet connected.`, 500);
}

// Create a page
Expand Down
13 changes: 8 additions & 5 deletions lib/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ export const fetchAndProcessScript = async (

if (shouldThrowError) {
throw new ExportError(
`Could not fetch the ${script}.js. The script might not exist in the requested version (status code: ${response.statusCode}).`
`Could not fetch the ${script}.js. The script might not exist in the requested version (status code: ${response.statusCode}).`,
500
).setError(response);
} else {
log(
Expand Down Expand Up @@ -186,9 +187,10 @@ export const fetchScripts = async (
port: proxyPort
});
} catch (error) {
throw new ExportError('[cache] Could not create a Proxy Agent.').setError(
error
);
throw new ExportError(
'[cache] Could not create a Proxy Agent.',
500
).setError(error);
}
}

Expand Down Expand Up @@ -270,7 +272,8 @@ export const updateCache = async (
return fetchedModules;
} catch (error) {
throw new ExportError(
'[cache] Unable to update the local Highcharts cache.'
'[cache] Unable to update the local Highcharts cache.',
500
).setError(error);
}
};
Expand Down
11 changes: 10 additions & 1 deletion lib/chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export const startExport = async (settings, endCallback) => {
);
} catch (error) {
return endCallback(
new ExportError('[chart] Error loading raw input.').setError(error)
new ExportError('[chart] Error loading raw input.', 400).setError(error)
);
}
}
Expand Down Expand Up @@ -527,6 +527,15 @@ const exportAsString = (stringToExport, options, endCallback) => {
// Try to parse to JSON and call the doExport function
const chartJSON = JSON.parse(stringToExport.replaceAll(/\t|\n|\r/g, ' '));

if (!chartJSON || typeof chartJSON !== 'object') {
return endCallback(
new ExportError(
'[chart] Invalid configuration provided - the options must be an object, not a string',
400
)
);
}

// If a correct JSON, do the export
return doExport(options, chartJSON, endCallback);
} catch (error) {
Expand Down
Loading