From be93f91311a7e0ed50bdda5bb5ba447d10806514 Mon Sep 17 00:00:00 2001 From: Michael Demetriou Date: Sun, 14 Jul 2019 15:26:14 +0300 Subject: [PATCH] Add error handling for HTTP response codes other than 200. This works also for local errors such as no connection as browsers return a response code of 0 in that case --- templates/pad.tmpl | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/templates/pad.tmpl b/templates/pad.tmpl index 3855068..e5f7e04 100644 --- a/templates/pad.tmpl +++ b/templates/pad.tmpl @@ -434,7 +434,11 @@ xhr.send(formData); xhr.onreadystatechange = function(){ if(xhr.readyState == 4){ - processResponse(xhr.responseText, file.identifier); + if (xhr.status == 200){ + processResponse(xhr.responseText, file.identifier); + } else { + processFailure(file.identifier); + } } } } @@ -445,6 +449,10 @@ textarea.value = textarea.value.replace(getMarkdownRegex(identifier), "["+ description +"]("+response.url+")"); } + function processFailure(identifier){ + textarea.value = textarea.value.replace(getMarkdownRegex(identifier), ""); + } + function getMarkdownRegex(identifier){ return new RegExp('\\[' + identifier + '\\]\\(.*?\\)'); }