Added Server Response Error Handling #1011
1 changed files with 23 additions and 8 deletions
|
@ -23,14 +23,29 @@ export const makePublishRequestChannel = (fd, isUpdate) => {
|
||||||
// set state change handler
|
// set state change handler
|
||||||
xhr.onreadystatechange = () => {
|
xhr.onreadystatechange = () => {
|
||||||
if (xhr.readyState === 4) {
|
if (xhr.readyState === 4) {
|
||||||
const response = JSON.parse(xhr.response);
|
switch (xhr.status) {
|
||||||
if ((xhr.status === 200) && response.success) {
|
case 413:
|
||||||
emitter({success: response});
|
emitter({error: new Error("Unfortunately it appears this web server " +
|
||||||
emitter(END);
|
"has been misconfigured, please inform the service administrators " +
|
||||||
} else {
|
"that they must set their nginx/apache request size maximums higher " +
|
||||||
emitter({error: new Error(response.message)});
|
"than their file size limits.")});
|
||||||
emitter(END);
|
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
|
// open and send
|
||||||
|
|
Loading…
Add table
Reference in a new issue