From 82ab3b47b196654fde126735e7de5aec03a8e4a2 Mon Sep 17 00:00:00 2001 From: ProfessorDey Date: Thu, 30 May 2019 14:33:53 +0100 Subject: [PATCH] Added Server Response Error Handling Presently the spee.ch client will error out if it received an unexpected response, resulting in hangs and a very vague JSON parsing error. This failsafe will catch the known issue of server request size limits causing 413 responses if misconfigured, making things easier to diagnose, as well as catching any other unexpected responses cleanly. Further specific behaviours can be added to ensure administrators spend less time debugging simple configuration issues. The 413 error response should be fairly self explanatory, sufficient to not need further documentation, though adding an addendum to the README.md would aid other developers have a smooth experience. --- client/src/channels/publish.js | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/client/src/channels/publish.js b/client/src/channels/publish.js index 0a89feb4..27595986 100644 --- a/client/src/channels/publish.js +++ b/client/src/channels/publish.js @@ -23,14 +23,29 @@ export const makePublishRequestChannel = (fd, isUpdate) => { // set state change handler xhr.onreadystatechange = () => { if (xhr.readyState === 4) { - const response = JSON.parse(xhr.response); - if ((xhr.status === 200) && response.success) { - emitter({success: response}); - emitter(END); - } else { - emitter({error: new Error(response.message)}); - emitter(END); - } + switch (xhr.status) { + case 413: + emitter({error: new Error("Unfortunately it appears this web server " + + "has been misconfigured, please inform the service administrators " + + "that they must set their nginx/apache request size maximums higher " + + "than their file size limits.")}); + emitter(END); + break; + case 200: + var response = JSON.parse(xhr.response); + if (response.success) { + emitter({success: response}); + emitter(END); + } else { + emitter({error: new Error(response.message)}); + emitter(END); + } + break; + default: + emitter({error: new Error("Received an unexpected response from " + + "server: " + xhr.status)}); + emitter(END); + } } }; // open and send