diff --git a/src/node_modules/renderImgOrSvg.js b/src/node_modules/renderImgOrSvg.js index eb93980..246eedc 100644 --- a/src/node_modules/renderImgOrSvg.js +++ b/src/node_modules/renderImgOrSvg.js @@ -95,7 +95,7 @@ module.exports = (render) => async (ctx, encodedCode, _next) => { debug('rendered SVG in DOM'); } catch (e) { debug('mermaid failed to render SVG: %o', e); - ctx.throw(400, 'invalid encoded code'); + ctx.throw(400, e); } await render(ctx, page, size); } catch (e) { diff --git a/src/static/mermaid.mjs b/src/static/mermaid.mjs index 22db0ce..2d3add2 100644 --- a/src/static/mermaid.mjs +++ b/src/static/mermaid.mjs @@ -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) { @@ -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; } }