mirror of https://github.com/zulip/zulip.git
upload: Handle JSON errors from server generically.
This commit is contained in:
parent
d053e07760
commit
b69873522b
|
@ -66,9 +66,9 @@ zrequire('upload');
|
|||
assert.equal($("#compose-error-msg").text(), msg);
|
||||
}
|
||||
|
||||
function test(err, file, msg) {
|
||||
function test(err, msg, server_response=null, file={}) {
|
||||
setup_test();
|
||||
upload.uploadError(err, null, file);
|
||||
upload.uploadError(err, server_response, file);
|
||||
assert_side_effects(msg);
|
||||
}
|
||||
|
||||
|
@ -79,11 +79,12 @@ zrequire('upload');
|
|||
var msg_4 = 'Sorry, the file was too large.';
|
||||
var msg_5 = 'An unknown error occurred.';
|
||||
|
||||
test('BrowserNotSupported', {}, msg_prefix + msg_1);
|
||||
test('TooManyFiles', {}, msg_prefix + msg_2);
|
||||
test('FileTooLarge', {name: 'foobar.txt'}, msg_prefix + msg_3);
|
||||
test(413, {}, msg_prefix + msg_4);
|
||||
test('Do-not-match-any-case', {}, msg_prefix + msg_5);
|
||||
test('BrowserNotSupported', msg_prefix + msg_1);
|
||||
test('TooManyFiles', msg_prefix + msg_2);
|
||||
test('FileTooLarge', msg_prefix + msg_3, null, {name: 'foobar.txt'});
|
||||
test(413, msg_prefix + msg_4);
|
||||
test(400, 'ちょっと…', {msg: 'ちょっと…'});
|
||||
test('Do-not-match-any-case', msg_prefix + msg_5);
|
||||
}());
|
||||
|
||||
(function test_upload_finish() {
|
||||
|
|
|
@ -57,6 +57,10 @@ exports.uploadError = function (error_code, server_response, file) {
|
|||
case 413: // HTTP status "Request Entity Too Large"
|
||||
msg = i18n.t("Sorry, the file was too large.");
|
||||
break;
|
||||
case 400:
|
||||
var server_message = server_response && server_response.msg;
|
||||
msg = server_message || i18n.t("An unknown error occurred.");
|
||||
break;
|
||||
default:
|
||||
msg = i18n.t("An unknown error occurred.");
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue