Skip to content

Commit

Permalink
Master changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulDalek committed Nov 4, 2024
2 parents 7a22f18 + d61b462 commit 33626cb
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ _New Features:_

- Added support for absolute paths in the `HIGHCHARTS_CACHE_PATH` option [(#562)](https://github.com/highcharts/node-export-server/issues/562)

_Fixes_:

- Improved status codes (user errors instead of 500) [(#577)](https://github.com/highcharts/node-export-server/pull/577)

- Improved memory management/usage [(#586)](https://github.com/highcharts/node-export-server/pull/586)

_Other:_

- Add fair usage policy note on the page [(#583)](https://github.com/highcharts/node-export-server/pull/583)

# 4.0.2

_Hotfix_:
Expand Down
2 changes: 1 addition & 1 deletion lib/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,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 @@ -268,7 +268,8 @@ async function _fetchAndProcessScript(

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 @@ -349,9 +350,10 @@ async function _fetchScripts(
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 @@ -439,7 +441,8 @@ async function _updateCache(highchartsOptions, serverProxyOptions, sourcePath) {
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 @@ -132,7 +132,7 @@ export async function startExport(options = getOptions(), endCallback) {
return _prepareExport(options, endCallback, exportOptions.instr, null);
} 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 @@ -350,6 +350,15 @@ function _exportAsString(stringToExport, options, endCallback) {
// Try to parse to JSON
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
)
);
}

// Call the `_prepareExport` with a chart JSON options
return _prepareExport(options, endCallback, chartJSON, null);
} catch (error) {
Expand Down
6 changes: 5 additions & 1 deletion lib/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ const app = express();
app.disable('x-powered-by');

// Enable CORS support
app.use(cors());
app.use(
cors({
methods: ['POST', 'GET', 'OPTIONS']
})
);

// Enable body parser for JSON data
app.use(
Expand Down

0 comments on commit 33626cb

Please sign in to comment.