Skip to content

Commit

Permalink
Merge pull request #425 from brendanator/return-parse-error
Browse files Browse the repository at this point in the history
feat: return mermaid parse error in 400 response
  • Loading branch information
jihchi authored Nov 4, 2024
2 parents 845fd06 + fae56a6 commit 99eefb1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 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.

10 changes: 5 additions & 5 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,10 +54,10 @@ 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;
throw error.message;
}
}

Expand Down

0 comments on commit 99eefb1

Please sign in to comment.