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