Simplify the form of catching ajax errors

This commit is contained in:
printempw 2017-08-01 12:24:32 +08:00
parent 07110d2580
commit 3e798d9cc5
11 changed files with 46 additions and 46 deletions

View File

@ -17,7 +17,7 @@ function submitColor() {
data: { color_scheme: current_skin } data: { color_scheme: current_skin }
}).then(({ errno, msg }) => { }).then(({ errno, msg }) => {
(errno == 0) ? toastr.success(msg) : toastr.warning(msg); (errno == 0) ? toastr.success(msg) : toastr.warning(msg);
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
$('#color-submit').click(submitColor); $('#color-submit').click(submitColor);

View File

@ -11,7 +11,7 @@ function changePreference() {
} }
}).then(({ errno, msg }) => { }).then(({ errno, msg }) => {
(errno == 0) ? toastr.success(msg) : toastr.warning(msg); (errno == 0) ? toastr.success(msg) : toastr.warning(msg);
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
function changeTexture(pid, playerName) { function changeTexture(pid, playerName) {
@ -58,7 +58,7 @@ function ajaxChangeTexture(pid) {
} else { } else {
toastr.warning(msg); toastr.warning(msg);
} }
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
function changePlayerName(pid, oldName) { function changePlayerName(pid, oldName) {
@ -85,7 +85,7 @@ function changePlayerName(pid, oldName) {
} else { } else {
toastr.warning(msg); toastr.warning(msg);
} }
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
function changeOwner(pid) { function changeOwner(pid) {
@ -113,7 +113,7 @@ function changeOwner(pid) {
} else { } else {
toastr.warning(msg); toastr.warning(msg);
} }
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
$('.swal2-input').on('input', debounce(() => { $('.swal2-input').on('input', debounce(() => {
let uid = $('.swal2-input').val(); let uid = $('.swal2-input').val();
@ -158,7 +158,7 @@ function deletePlayer(pid) {
} else { } else {
toastr.warning(msg); toastr.warning(msg);
} }
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
if (typeof require !== 'undefined' && typeof module !== 'undefined') { if (typeof require !== 'undefined' && typeof module !== 'undefined') {

View File

@ -13,7 +13,7 @@ function enablePlugin(name) {
} else { } else {
toastr.warning(msg); toastr.warning(msg);
} }
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
function disablePlugin(name) { function disablePlugin(name) {
@ -29,7 +29,7 @@ function disablePlugin(name) {
} else { } else {
toastr.warning(msg); toastr.warning(msg);
} }
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
function deletePlugin(name) { function deletePlugin(name) {
@ -49,7 +49,7 @@ function deletePlugin(name) {
} else { } else {
toastr.warning(msg); toastr.warning(msg);
} }
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
if (typeof require !== 'undefined' && typeof module !== 'undefined') { if (typeof require !== 'undefined' && typeof module !== 'undefined') {

View File

@ -39,7 +39,7 @@ function downloadUpdates() {
console.log('Downloading finished'); console.log('Downloading finished');
console.log(json); console.log(json);
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
// Downloading progress polling // Downloading progress polling
let interval_id = window.setInterval(() => { let interval_id = window.setInterval(() => {
@ -70,7 +70,7 @@ function downloadUpdates() {
}, function() { }, function() {
window.location = url('/'); window.location = url('/');
}); });
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} else { } else {
fetch({ fetch({
@ -80,11 +80,11 @@ function downloadUpdates() {
progress = (json.size / fileSize * 100).toFixed(2); progress = (json.size / fileSize * 100).toFixed(2);
console.log('Progress: ' + progress); console.log('Progress: ' + progress);
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
}, 300); }, 300);
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }

View File

@ -25,7 +25,7 @@ function changeUserEmail(uid) {
} else { } else {
toastr.warning(msg); toastr.warning(msg);
} }
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
function changeUserNickName(uid) { function changeUserNickName(uid) {
@ -53,7 +53,7 @@ function changeUserNickName(uid) {
} else { } else {
toastr.warning(msg); toastr.warning(msg);
} }
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
function changeUserPwd(uid) { function changeUserPwd(uid) {
@ -68,7 +68,7 @@ function changeUserPwd(uid) {
data: { uid: uid, password: password } data: { uid: uid, password: password }
})).then(({ errno, msg }) => { })).then(({ errno, msg }) => {
(errno == 0) ? toastr.success(msg) : toastr.warning(msg); (errno == 0) ? toastr.success(msg) : toastr.warning(msg);
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
function changeUserScore(uid, score) { function changeUserScore(uid, score) {
@ -80,7 +80,7 @@ function changeUserScore(uid, score) {
data: { uid: uid.slice(5), score: score } data: { uid: uid.slice(5), score: score }
}).then(({ errno, msg }) => { }).then(({ errno, msg }) => {
(errno == 0) ? toastr.success(msg) : toastr.warning(msg); (errno == 0) ? toastr.success(msg) : toastr.warning(msg);
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
function changeBanStatus(uid) { function changeBanStatus(uid) {
@ -107,7 +107,7 @@ function changeBanStatus(uid) {
} else { } else {
toastr.warning(msg); toastr.warning(msg);
} }
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
function changeAdminStatus(uid) { function changeAdminStatus(uid) {
@ -134,7 +134,7 @@ function changeAdminStatus(uid) {
} else { } else {
toastr.warning(msg); toastr.warning(msg);
} }
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
function deleteUserAccount(uid) { function deleteUserAccount(uid) {
@ -154,7 +154,7 @@ function deleteUserAccount(uid) {
} else { } else {
toastr.warning(msg); toastr.warning(msg);
} }
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
$('body').on('keypress', '.score', function(event){ $('body').on('keypress', '.score', function(event){

View File

@ -33,7 +33,7 @@ class TexturePreview {
} else { } else {
MSP.changeSkin(textureUrl); MSP.changeSkin(textureUrl);
} }
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
return this; return this;

View File

@ -47,7 +47,7 @@ function ajaxAddToCloset(tid, name) {
} else { } else {
toastr.warning(msg); toastr.warning(msg);
} }
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
function removeFromCloset(tid) { function removeFromCloset(tid) {
@ -70,7 +70,7 @@ function removeFromCloset(tid) {
} else { } else {
toastr.warning(msg); toastr.warning(msg);
} }
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
function changeTextureName(tid, oldName) { function changeTextureName(tid, oldName) {
@ -96,7 +96,7 @@ function changeTextureName(tid, oldName) {
} else { } else {
toastr.warning(msg); toastr.warning(msg);
} }
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
/** /**
@ -151,7 +151,7 @@ function changePrivacy(tid) {
} else { } else {
toastr.warning(msg); toastr.warning(msg);
} }
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
function deleteTexture(tid) { function deleteTexture(tid) {
@ -172,7 +172,7 @@ function deleteTexture(tid) {
} else { } else {
swal({ type: 'warning', html: msg }); swal({ type: 'warning', html: msg });
} }
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
if (typeof require !== 'undefined' && typeof module !== 'undefined') { if (typeof require !== 'undefined' && typeof module !== 'undefined') {

View File

@ -26,7 +26,7 @@ $(document).ready(function () {
page, $('input[name=q]').val() page, $('input[name=q]').val()
) )
})); }));
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
$('input[name=q]').on('input', debounce(() => { $('input[name=q]').on('input', debounce(() => {
let category = $('#skin-category').hasClass('active') ? 'skin' : 'cape'; let category = $('#skin-category').hasClass('active') ? 'skin' : 'cape';
@ -67,7 +67,7 @@ $('body').on('click', '.item-body', function () {
} else if (cape != undefined) { } else if (cape != undefined) {
$indicator.text(trans('general.cape')); $indicator.text(trans('general.cape'));
} }
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
}); });
$('body').on('click', '.category-switch', () => { $('body').on('click', '.category-switch', () => {
@ -158,7 +158,7 @@ function reloadCloset(category, page, search) {
currentPage: page, currentPage: page,
totalPages: total_pages totalPages: total_pages
}); });
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
function renameClosetItem(tid, oldName) { function renameClosetItem(tid, oldName) {
@ -184,7 +184,7 @@ function renameClosetItem(tid, oldName) {
} else { } else {
toastr.warning(msg); toastr.warning(msg);
} }
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
function removeFromCloset(tid) { function removeFromCloset(tid) {
@ -214,7 +214,7 @@ function removeFromCloset(tid) {
} else { } else {
toastr.warning(msg); toastr.warning(msg);
} }
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
function setAsAvatar(tid) { function setAsAvatar(tid) {
@ -239,7 +239,7 @@ function setAsAvatar(tid) {
} else { } else {
toastr.warning(msg); toastr.warning(msg);
} }
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
if (typeof require !== 'undefined' && typeof module !== 'undefined') { if (typeof require !== 'undefined' && typeof module !== 'undefined') {

View File

@ -17,7 +17,7 @@ $('body').on('click', '.player', function () {
data: { pid: $(this).attr('pid'), preference: $(this).val() } data: { pid: $(this).attr('pid'), preference: $(this).val() }
}).then(({ errno, msg }) => { }).then(({ errno, msg }) => {
(errno == 0) ? toastr.success(msg) : toastr.warning(msg); (errno == 0) ? toastr.success(msg) : toastr.warning(msg);
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
}); });
function showPlayerTexturePreview(pid) { function showPlayerTexturePreview(pid) {
@ -48,7 +48,7 @@ function showPlayerTexturePreview(pid) {
console.log(`Texture previews of player ${result.player_name} rendered.`); console.log(`Texture previews of player ${result.player_name} rendered.`);
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
function changePlayerName(pid) { function changePlayerName(pid) {
@ -77,7 +77,7 @@ function changePlayerName(pid) {
} else { } else {
swal({ type: 'error', html: msg }); swal({ type: 'error', html: msg });
} }
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
function clearTexture(pid) { function clearTexture(pid) {
@ -122,7 +122,7 @@ function ajaxClearTexture(pid) {
}).then(({ errno, msg }) => { }).then(({ errno, msg }) => {
swal({ type: errno == 0 ? 'success' : 'error', html: msg }); swal({ type: errno == 0 ? 'success' : 'error', html: msg });
$('.modal').modal('hide'); $('.modal').modal('hide');
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
function deletePlayer(pid) { function deletePlayer(pid) {
@ -147,7 +147,7 @@ function deletePlayer(pid) {
} else { } else {
swal({ type: 'error', html: msg }); swal({ type: 'error', html: msg });
} }
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
function addNewPlayer() { function addNewPlayer() {
@ -167,7 +167,7 @@ function addNewPlayer() {
} else { } else {
toastr.warning(msg); toastr.warning(msg);
} }
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
function setTexture() { function setTexture() {
@ -200,7 +200,7 @@ function setTexture() {
} else { } else {
toastr.warning(msg); toastr.warning(msg);
} }
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
} }

View File

@ -27,7 +27,7 @@ function changeNickName() {
} else { } else {
return swal({ type: 'warning', html: msg }); return swal({ type: 'warning', html: msg });
} }
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
function changePassword() { function changePassword() {
@ -67,11 +67,11 @@ function changePassword() {
if (errno == 0) { if (errno == 0) {
window.location = url('auth/login'); window.location = url('auth/login');
} }
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} else { } else {
return swal({ type: 'warning', text: msg }); return swal({ type: 'warning', text: msg });
} }
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
} }
@ -117,11 +117,11 @@ function changeEmail() {
if (errno == 0) { if (errno == 0) {
window.location = url('auth/login'); window.location = url('auth/login');
} }
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} else { } else {
return swal({ type: 'warning', text: msg }); return swal({ type: 'warning', text: msg });
} }
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
function deleteAccount() { function deleteAccount() {
@ -147,7 +147,7 @@ function deleteAccount() {
} else { } else {
return swal({ type: 'warning', html: msg }); return swal({ type: 'warning', html: msg });
} }
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
if (typeof require !== 'undefined' && typeof module !== 'undefined') { if (typeof require !== 'undefined' && typeof module !== 'undefined') {

View File

@ -24,7 +24,7 @@ function sign() {
} else { } else {
toastr.warning(result.msg); toastr.warning(result.msg);
} }
}).catch(err => showAjaxError(err)); }).catch(showAjaxError);
} }
if (typeof require !== 'undefined' && typeof module !== 'undefined') { if (typeof require !== 'undefined' && typeof module !== 'undefined') {