From 1b50ce60150af71319a5828085aff693664f521c Mon Sep 17 00:00:00 2001 From: ruesin Date: Thu, 29 Nov 2018 15:04:18 +0800 Subject: [PATCH] catch json-parse error --- src/js/simplemde.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/js/simplemde.js b/src/js/simplemde.js index 33d576e..f69a769 100644 --- a/src/js/simplemde.js +++ b/src/js/simplemde.js @@ -679,9 +679,13 @@ function uploadImage(editor) { xmlhttp.send(formData); xmlhttp.onreadystatechange = function() { if(xmlhttp.readyState == 4 && xmlhttp.status == 200) { - var res = JSON.parse(xmlhttp.responseText); - if(res.url) { - editor.codemirror.replaceSelection("![" + (res.name || file.name) + "](" + res.url + ")"); + try { + var res = JSON.parse(xmlhttp.responseText); + if(res.url) { + editor.codemirror.replaceSelection("![" + (res.name || file.name) + "](" + res.url + ")"); + } + } catch (e) { + editor.codemirror.replaceSelection("![]()"); } } };