Skip to content

Commit

Permalink
feat: return mermaid parse error in 400 response
Browse files Browse the repository at this point in the history
  • Loading branch information
brendanator committed Oct 22, 2024
1 parent a84b270 commit cf90d8b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/node_modules/renderImgOrSvg.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/static/mermaid.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import mermaid from '../../node_modules/mermaid/dist/mermaid.esm.min.mjs';

function isSyntaxErrorFromMermaid(code) {
return code.includes('Syntax error in graph') && code.includes('error-icon');
function isUnknownDiagramError(code) {
return code.includes('UnknownDiagramError');
}

function setBgColor(svgElement, bgColor) {
Expand Down Expand Up @@ -54,8 +54,8 @@ async function render(definition, config, bgColor, size) {
}
} catch (error) {
console.error('Failed to render', error);
if (isSyntaxErrorFromMermaid(error.toString())) {
throw new Error('Syntax error in graph');
if (isUnknownDiagramError(error.toString())) {
throw new Error('Unknown diagram error');
}
throw error;
}
Expand Down

0 comments on commit cf90d8b

Please sign in to comment.