mirror of
https://github.com/octoleo/plantuml-server.git
synced 2024-12-22 08:48:54 +00:00
catch 400 response for broken diagrams
This commit is contained in:
parent
178384370f
commit
5fa6cbc82f
@ -57,21 +57,27 @@ async function setDiagram(type, encodedDiagram, index) {
|
|||||||
setVisibility(pdf, type === "pdf");
|
setVisibility(pdf, type === "pdf");
|
||||||
}
|
}
|
||||||
// update diagram
|
// update diagram
|
||||||
if (type === "png") {
|
try {
|
||||||
png.src = buildUrl("png", encodedDiagram, index);
|
if (type === "png") {
|
||||||
const map = await requestDiagram("map", encodedDiagram, index);
|
png.src = buildUrl("png", encodedDiagram, index);
|
||||||
setDiagramMap(map);
|
const map = await requestDiagram("map", encodedDiagram, index);
|
||||||
} else if (type === "svg") {
|
setDiagramMap(map);
|
||||||
const svg = await requestDiagram("svg", encodedDiagram, index);
|
} else if (type === "svg") {
|
||||||
setSvgDiagram(svg);
|
const svg = await requestDiagram("svg", encodedDiagram, index);
|
||||||
} else if (type === "txt") {
|
setSvgDiagram(svg);
|
||||||
txt.innerHTML = await requestDiagram("txt", encodedDiagram, index);
|
} else if (type === "txt") {
|
||||||
} else if (type === "pdf") {
|
txt.innerHTML = await requestDiagram("txt", encodedDiagram, index);
|
||||||
pdf.data = buildUrl("pdf", encodedDiagram, index);
|
} else if (type === "pdf") {
|
||||||
} else {
|
pdf.data = buildUrl("pdf", encodedDiagram, index);
|
||||||
const message = "unknown diagram type: " + type;
|
} else {
|
||||||
(console.error || console.log)(message);
|
const message = "unknown diagram type: " + type;
|
||||||
return Promise.reject(message);
|
(console.error || console.log)(message);
|
||||||
|
return Promise.reject(message);
|
||||||
|
}
|
||||||
|
setDiagramVisibility(type);
|
||||||
|
} catch (e) {
|
||||||
|
// This should only happen if for example a broken diagram is requested.
|
||||||
|
// Therefore, since the error message is already included in the response image, prevent further error messages.
|
||||||
|
//(console.error || console.log)(e);
|
||||||
}
|
}
|
||||||
setDiagramVisibility(type);
|
|
||||||
}
|
}
|
||||||
|
9
src/main/webapp/min/plantuml.min.js
vendored
9
src/main/webapp/min/plantuml.min.js
vendored
@ -52,10 +52,11 @@ function initSettings(){function a(){setVisibility(document.getElementById("sett
|
|||||||
Object.assign({},{language:"json"},document.appConfig.editorCreateOptions));b.addEventListener("change",function(e){e=e.target.value;var f=document.settingsEditor.getValue();setEditorValue(document.settingsEditor,f.replace(new RegExp('("theme"\\s*:\\s*)"'+("dark"===e?"vs":"vs-dark")+'"',"gm"),'$1"'+("dark"===e?"vs-dark":"vs")+'"'))});document.getElementById("settings-ok-btn").addEventListener("click",function(){var e=Object.assign({},document.appConfig);e.theme=b.value;e.editorWatcherTimeout=d.value;
|
Object.assign({},{language:"json"},document.appConfig.editorCreateOptions));b.addEventListener("change",function(e){e=e.target.value;var f=document.settingsEditor.getValue();setEditorValue(document.settingsEditor,f.replace(new RegExp('("theme"\\s*:\\s*)"'+("dark"===e?"vs":"vs-dark")+'"',"gm"),'$1"'+("dark"===e?"vs-dark":"vs")+'"'))});document.getElementById("settings-ok-btn").addEventListener("click",function(){var e=Object.assign({},document.appConfig);e.theme=b.value;e.editorWatcherTimeout=d.value;
|
||||||
e.diagramPreviewType=c.value;e.editorCreateOptions=JSON.parse(document.settingsEditor.getValue());updateConfig(e);closeModal("settings")});window.addEventListener("keydown",function(e){","===e.key&&(isMac?e.metaKey:e.ctrlKey)&&(e.preventDefault(),isModalOpen("settings")||a())},!1);registerModalListener("settings",a)}
|
e.diagramPreviewType=c.value;e.editorCreateOptions=JSON.parse(document.settingsEditor.getValue());updateConfig(e);closeModal("settings")});window.addEventListener("keydown",function(e){","===e.key&&(isMac?e.metaKey:e.ctrlKey)&&(e.preventDefault(),isModalOpen("settings")||a())},!1);registerModalListener("settings",a)}
|
||||||
function initializeDiagram(){return $jscomp.asyncExecutePromiseGeneratorProgram(function(a){if("png"!==document.appConfig.diagramPreviewType)return a.return(setDiagram(document.appConfig.diagramPreviewType,document.appData.encodedDiagram,document.appData.index));a.jumpToEnd()})}
|
function initializeDiagram(){return $jscomp.asyncExecutePromiseGeneratorProgram(function(a){if("png"!==document.appConfig.diagramPreviewType)return a.return(setDiagram(document.appConfig.diagramPreviewType,document.appData.encodedDiagram,document.appData.index));a.jumpToEnd()})}
|
||||||
function setDiagram(a,b,c){function d(k,n,q){return $jscomp.asyncExecutePromiseGeneratorProgram(function(r){return r.return(makeRequest("GET",buildUrl(k,n,q)))})}var e,f,g,m,l,h,t,p;return $jscomp.asyncExecutePromiseGeneratorProgram(function(k){switch(k.nextAddress){case 1:e=document.getElementById("diagram");f=document.getElementById("diagram-png");g=document.getElementById("diagram-txt");m=document.getElementById("diagram-pdf");if("png"===a)return f.src=buildUrl("png",b,c),k.yield(d("map",b,c),
|
function setDiagram(a,b,c){function d(k,n,q){return $jscomp.asyncExecutePromiseGeneratorProgram(function(r){return r.return(makeRequest("GET",buildUrl(k,n,q)))})}var e,f,g,m,l,h,t,p;return $jscomp.asyncExecutePromiseGeneratorProgram(function(k){switch(k.nextAddress){case 1:e=document.getElementById("diagram");f=document.getElementById("diagram-png");g=document.getElementById("diagram-txt");m=document.getElementById("diagram-pdf");k.setCatchFinallyBlocks(2);if("png"===a)return f.src=buildUrl("png",
|
||||||
9);if("svg"===a)return k.yield(d("svg",b,c),8);if("txt"!==a){if("pdf"===a)m.data=buildUrl("pdf",b,c);else return l="unknown diagram type: "+a,(console.error||console.log)(l),k.return(Promise.reject(l));k.jumpTo(3);break}h=g;return k.yield(d("txt",b,c),7);case 7:h.innerHTML=k.yieldResult;k.jumpTo(3);break;case 8:t=k.yieldResult;var n=document.getElementById("diagram-svg"),q=document.createElement("div");q.innerHTML=t;q=q.querySelector("svg");q.id="diagram-svg";q.classList=n.classList;q.style.cssText=
|
b,c),k.yield(d("map",b,c),11);if("svg"===a)return k.yield(d("svg",b,c),10);if("txt"!==a){if("pdf"===a)m.data=buildUrl("pdf",b,c);else return l="unknown diagram type: "+a,(console.error||console.log)(l),k.return(Promise.reject(l));k.jumpTo(5);break}h=g;return k.yield(d("txt",b,c),9);case 9:h.innerHTML=k.yieldResult;k.jumpTo(5);break;case 10:t=k.yieldResult;var n=document.getElementById("diagram-svg"),q=document.createElement("div");q.innerHTML=t;q=q.querySelector("svg");q.id="diagram-svg";q.classList=
|
||||||
n.style.cssText;n.parentNode.replaceChild(q,n);k.jumpTo(3);break;case 9:if(p=k.yieldResult,n=document.getElementById("plantuml_map"),q=document.getElementById("map-diagram-link"),p){var r=document.createElement("div");r.innerHTML=p;n.parentNode.replaceChild(r.firstChild,n);setVisibility(q,!0)}else removeChildren(n),setVisibility(q,!1);case 3:n=document.getElementById("plantuml_map"),q=document.getElementById("diagram-svg"),e.setAttribute("data-diagram-type",a),setVisibility(f,"png"===a),setVisibility(n,
|
n.classList;q.style.cssText=n.style.cssText;n.parentNode.replaceChild(q,n);k.jumpTo(5);break;case 11:if(p=k.yieldResult,n=document.getElementById("plantuml_map"),q=document.getElementById("map-diagram-link"),p){var r=document.createElement("div");r.innerHTML=p;n.parentNode.replaceChild(r.firstChild,n);setVisibility(q,!0)}else removeChildren(n),setVisibility(q,!1);case 5:n=document.getElementById("plantuml_map");q=document.getElementById("diagram-svg");e.setAttribute("data-diagram-type",a);setVisibility(f,
|
||||||
"png"===a),setVisibility(q,"svg"===a),setVisibility(g,"txt"===a),setVisibility(m,"pdf"===a),k.jumpToEnd()}})}function getNumberOfDiagramPagesFromCode(a){var b;return(null==(b=a.match(/^\s*newpage\s?.*$/gm))?void 0:b.length)+1||1}function updatePaginatorSelection(){var a=document.getElementById("paginator"),b=document.appData.index;if(void 0===b||a.childNodes.length<=b)for(a=$jscomp.makeIterator(a.childNodes),b=a.next();!b.done;b=a.next())b.value.checked=!1;else a.childNodes[b].checked=!0}
|
"png"===a);setVisibility(n,"png"===a);setVisibility(q,"svg"===a);setVisibility(g,"txt"===a);setVisibility(m,"pdf"===a);k.leaveTryBlock(0);break;case 2:k.enterCatchBlock(),k.jumpToEnd()}})}function getNumberOfDiagramPagesFromCode(a){var b;return(null==(b=a.match(/^\s*newpage\s?.*$/gm))?void 0:b.length)+1||1}
|
||||||
|
function updatePaginatorSelection(){var a=document.getElementById("paginator"),b=document.appData.index;if(void 0===b||a.childNodes.length<=b)for(a=$jscomp.makeIterator(a.childNodes),b=a.next();!b.done;b=a.next())b.value.checked=!1;else a.childNodes[b].checked=!0}
|
||||||
var updatePaginator=function(){function a(b,c){for(;b.childElementCount>c;)b.removeChild(b.lastChild);for(;b.childElementCount<c;){var d=document.createElement("input");d.name="paginator";d.type="radio";d.value=b.childElementCount;d.addEventListener("click",function(e){sendMessage({sender:"paginator",data:{index:e.target.value},synchronize:!0})});b.appendChild(d)}}return function(){var b=document.getElementById("paginator"),c=document.appData.numberOfDiagramPages;1<c?(a(b,c),setVisibility(b,!0)):
|
var updatePaginator=function(){function a(b,c){for(;b.childElementCount>c;)b.removeChild(b.lastChild);for(;b.childElementCount<c;){var d=document.createElement("input");d.name="paginator";d.type="radio";d.value=b.childElementCount;d.addEventListener("click",function(e){sendMessage({sender:"paginator",data:{index:e.target.value},synchronize:!0})});b.appendChild(d)}}return function(){var b=document.getElementById("paginator"),c=document.appData.numberOfDiagramPages;1<c?(a(b,c),setVisibility(b,!0)):
|
||||||
setVisibility(b,!1)}}();function initializePaginator(){1<document.appData.numberOfDiagramPages&&(updatePaginator(),updatePaginatorSelection())}
|
setVisibility(b,!1)}}();function initializePaginator(){1<document.appData.numberOfDiagramPages&&(updatePaginator(),updatePaginatorSelection())}
|
||||||
function initPreview(a){function b(){setVisibility(e,!1);setVisibility(f,window.opener);g&&(g.style.width="100%");m&&setVisibility(m,!1)}function c(){setVisibility(e,!0);setVisibility(f,!1);g&&g.style.removeProperty("width");m&&setVisibility(m,!0)}function d(){var l=new URL(window.location.href);l.searchParams.set("view","previewer");if(l=window.open(l,"PlantUML Diagram Previewer","popup"))l.onbeforeunload=c,b()}var e,f,g,m;return $jscomp.asyncExecutePromiseGeneratorProgram(function(l){if(1==l.nextAddress)return e=
|
function initPreview(a){function b(){setVisibility(e,!1);setVisibility(f,window.opener);g&&(g.style.width="100%");m&&setVisibility(m,!1)}function c(){setVisibility(e,!0);setVisibility(f,!1);g&&g.style.removeProperty("width");m&&setVisibility(m,!0)}function d(){var l=new URL(window.location.href);l.searchParams.set("view","previewer");if(l=window.open(l,"PlantUML Diagram Previewer","popup"))l.onbeforeunload=c,b()}var e,f,g,m;return $jscomp.asyncExecutePromiseGeneratorProgram(function(l){if(1==l.nextAddress)return e=
|
||||||
|
Loading…
Reference in New Issue
Block a user