client: rework promise error handling
This commit is contained in:
parent
5c0765c30e
commit
8a73f7e400
|
@ -85,18 +85,10 @@ class Api extends events.EventTarget {
|
||||||
}
|
}
|
||||||
|
|
||||||
loginFromCookies() {
|
loginFromCookies() {
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const auth = cookies.getJSON('auth');
|
const auth = cookies.getJSON('auth');
|
||||||
if (auth && auth.user && auth.password) {
|
return auth && auth.user && auth.password ?
|
||||||
this.login(auth.user, auth.password, true)
|
this.login(auth.user, auth.password, true) :
|
||||||
.then(resolve)
|
Promise.resolve();
|
||||||
.catch(errorMessage => {
|
|
||||||
reject(errorMessage);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
resolve();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
login(userName, userPassword, doRemember) {
|
login(userName, userPassword, doRemember) {
|
||||||
|
@ -117,8 +109,8 @@ class Api extends events.EventTarget {
|
||||||
this.user = response;
|
this.user = response;
|
||||||
resolve();
|
resolve();
|
||||||
this.dispatchEvent(new CustomEvent('login'));
|
this.dispatchEvent(new CustomEvent('login'));
|
||||||
}, response => {
|
}, error => {
|
||||||
reject(response.description || response || 'Unknown error');
|
reject(error);
|
||||||
this.logout();
|
this.logout();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -182,9 +174,9 @@ class Api extends events.EventTarget {
|
||||||
}
|
}
|
||||||
promise = promise.then(() => {
|
promise = promise.then(() => {
|
||||||
return this._rawRequest(url, requestFactory, data, {}, options);
|
return this._rawRequest(url, requestFactory, data, {}, options);
|
||||||
}, errorMessage => {
|
}, error => {
|
||||||
// TODO: check if the error is because of expired uploads
|
// TODO: check if the error is because of expired uploads
|
||||||
return Promise.reject(errorMessage);
|
return Promise.reject(error);
|
||||||
});
|
});
|
||||||
promise.abort = () => abortFunction();
|
promise.abort = () => abortFunction();
|
||||||
return promise;
|
return promise;
|
||||||
|
@ -201,7 +193,7 @@ class Api extends events.EventTarget {
|
||||||
resolve(response.token);
|
resolve(response.token);
|
||||||
abortFunction = () => {};
|
abortFunction = () => {};
|
||||||
},
|
},
|
||||||
errorMessage => reject(errorMessage));
|
reject);
|
||||||
});
|
});
|
||||||
returnedPromise.abort = () => abortFunction();
|
returnedPromise.abort = () => abortFunction();
|
||||||
return returnedPromise;
|
return returnedPromise;
|
||||||
|
@ -253,9 +245,8 @@ class Api extends events.EventTarget {
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
reject({
|
reject(
|
||||||
title: 'Authentication error',
|
new Error('Authentication error (malformed credentials)'));
|
||||||
description: 'Malformed credentials'});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!options.noProgress) {
|
if (!options.noProgress) {
|
||||||
|
@ -265,18 +256,19 @@ class Api extends events.EventTarget {
|
||||||
abortFunction = () => {
|
abortFunction = () => {
|
||||||
req.abort(); // does *NOT* call the callback passed in .end()
|
req.abort(); // does *NOT* call the callback passed in .end()
|
||||||
nprogress.done();
|
nprogress.done();
|
||||||
reject({
|
reject(
|
||||||
title: 'Cancelled',
|
new Error('The request was aborted due to user cancel.'));
|
||||||
description:
|
|
||||||
'The request was aborted due to user cancel.'});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
req.end((error, response) => {
|
req.end((error, response) => {
|
||||||
nprogress.done();
|
nprogress.done();
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(response && response.body ? response.body : {
|
if (response && response.body) {
|
||||||
title: 'Networking error',
|
error = new Error(
|
||||||
description: error.message});
|
response.body.description || 'Unknown error');
|
||||||
|
error.response = response.body;
|
||||||
|
}
|
||||||
|
reject(error);
|
||||||
} else {
|
} else {
|
||||||
resolve(response.body);
|
resolve(response.body);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,8 @@ class LoginController {
|
||||||
.then(() => {
|
.then(() => {
|
||||||
const ctx = router.show('/');
|
const ctx = router.show('/');
|
||||||
ctx.controller.showSuccess('Logged in');
|
ctx.controller.showSuccess('Logged in');
|
||||||
}, errorMessage => {
|
}, error => {
|
||||||
this._loginView.showError(errorMessage);
|
this._loginView.showError(error.message);
|
||||||
this._loginView.enableForm();
|
this._loginView.enableForm();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,24 +51,20 @@ class CommentsController {
|
||||||
// TODO: disable form
|
// TODO: disable form
|
||||||
e.detail.comment.text = e.detail.text;
|
e.detail.comment.text = e.detail.text;
|
||||||
e.detail.comment.save()
|
e.detail.comment.save()
|
||||||
.catch(errorMessage => {
|
.catch(error => {
|
||||||
e.detail.target.showError(errorMessage);
|
e.detail.target.showError(error.message);
|
||||||
// TODO: enable form
|
// TODO: enable form
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_evtScore(e) {
|
_evtScore(e) {
|
||||||
e.detail.comment.setScore(e.detail.score)
|
e.detail.comment.setScore(e.detail.score)
|
||||||
.catch(errorMessage => {
|
.catch(error => window.alert(error.message));
|
||||||
window.alert(errorMessage);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_evtDelete(e) {
|
_evtDelete(e) {
|
||||||
e.detail.comment.delete()
|
e.detail.comment.delete()
|
||||||
.catch(errorMessage => {
|
.catch(error => window.alert(error.message));
|
||||||
window.alert(errorMessage);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -31,9 +31,7 @@ class HomeController {
|
||||||
featuringTime: info.featuringTime,
|
featuringTime: info.featuringTime,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
errorMessage => {
|
error => this._homeView.showError(error.message));
|
||||||
this._homeView.showError(errorMessage);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
showSuccess(message) {
|
showSuccess(message) {
|
||||||
|
|
|
@ -25,8 +25,8 @@ class PasswordResetController {
|
||||||
this._passwordResetView.showSuccess(
|
this._passwordResetView.showSuccess(
|
||||||
'E-mail has been sent. To finish the procedure, ' +
|
'E-mail has been sent. To finish the procedure, ' +
|
||||||
'please click the link it contains.');
|
'please click the link it contains.');
|
||||||
}, response => {
|
}, error => {
|
||||||
this._passwordResetView.showError(response.description);
|
this._passwordResetView.showError(error.message);
|
||||||
this._passwordResetView.enableForm();
|
this._passwordResetView.enableForm();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -41,14 +41,12 @@ class PasswordResetFinishController {
|
||||||
.then(response => {
|
.then(response => {
|
||||||
password = response.password;
|
password = response.password;
|
||||||
return api.login(name, password, false);
|
return api.login(name, password, false);
|
||||||
}, response => {
|
|
||||||
return Promise.reject(response.description);
|
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
const ctx = router.show('/');
|
const ctx = router.show('/');
|
||||||
ctx.controller.showSuccess('New password: ' + password);
|
ctx.controller.showSuccess('New password: ' + password);
|
||||||
}, errorMessage => {
|
}, error => {
|
||||||
const ctx = router.show('/');
|
const ctx = router.show('/');
|
||||||
ctx.controller.showError(errorMessage);
|
ctx.controller.showError(error.message);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,11 +17,10 @@ class PostDetailController extends BasePostController {
|
||||||
Post.get(ctx.parameters.id).then(post => {
|
Post.get(ctx.parameters.id).then(post => {
|
||||||
this._id = ctx.parameters.id;
|
this._id = ctx.parameters.id;
|
||||||
post.addEventListener('change', e => this._evtSaved(e, section));
|
post.addEventListener('change', e => this._evtSaved(e, section));
|
||||||
|
|
||||||
this._installView(post, section);
|
this._installView(post, section);
|
||||||
}, errorMessage => {
|
}, error => {
|
||||||
this._view = new EmptyView();
|
this._view = new EmptyView();
|
||||||
this._view.showError(errorMessage);
|
this._view.showError(error.message);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,8 +45,8 @@ class PostDetailController extends BasePostController {
|
||||||
Post.get(e.detail.postId).then(post => {
|
Post.get(e.detail.postId).then(post => {
|
||||||
this._view.selectPost(post);
|
this._view.selectPost(post);
|
||||||
this._view.enableForm();
|
this._view.enableForm();
|
||||||
}, errorMessage => {
|
}, error => {
|
||||||
this._view.showError(errorMessage);
|
this._view.showError(error.message);
|
||||||
this._view.enableForm();
|
this._view.enableForm();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -69,8 +68,8 @@ class PostDetailController extends BasePostController {
|
||||||
this._view.showSuccess('Post merged.');
|
this._view.showSuccess('Post merged.');
|
||||||
router.replace(
|
router.replace(
|
||||||
'/post/' + e.detail.targetPost.id + '/merge', null, false);
|
'/post/' + e.detail.targetPost.id + '/merge', null, false);
|
||||||
}, errorMessage => {
|
}, error => {
|
||||||
this._view.showError(errorMessage);
|
this._view.showError(error.message);
|
||||||
this._view.enableForm();
|
this._view.enableForm();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,20 +61,14 @@ class PostListController {
|
||||||
for (let tag of this._massTagTags) {
|
for (let tag of this._massTagTags) {
|
||||||
e.detail.post.addTag(tag);
|
e.detail.post.addTag(tag);
|
||||||
}
|
}
|
||||||
e.detail.post.save()
|
e.detail.post.save().catch(error => window.alert(error.message));
|
||||||
.catch(errorMessage => {
|
|
||||||
window.alert(errorMessage);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_evtUntag(e) {
|
_evtUntag(e) {
|
||||||
for (let tag of this._massTagTags) {
|
for (let tag of this._massTagTags) {
|
||||||
e.detail.post.removeTag(tag);
|
e.detail.post.removeTag(tag);
|
||||||
}
|
}
|
||||||
e.detail.post.save()
|
e.detail.post.save().catch(error => window.alert(error.message));
|
||||||
.catch(errorMessage => {
|
|
||||||
window.alert(errorMessage);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_decorateSearchQuery(text) {
|
_decorateSearchQuery(text) {
|
||||||
|
|
|
@ -84,9 +84,9 @@ class PostMainController extends BasePostController {
|
||||||
this._view.commentListControl.addEventListener(
|
this._view.commentListControl.addEventListener(
|
||||||
'delete', e => this._evtDeleteComment(e));
|
'delete', e => this._evtDeleteComment(e));
|
||||||
}
|
}
|
||||||
}, errorMessage => {
|
}, error => {
|
||||||
this._view = new EmptyView();
|
this._view = new EmptyView();
|
||||||
this._view.showError(errorMessage);
|
this._view.showError(error.message);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,8 +117,8 @@ class PostMainController extends BasePostController {
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this._view.sidebarControl.showSuccess('Post featured.');
|
this._view.sidebarControl.showSuccess('Post featured.');
|
||||||
this._view.sidebarControl.enableForm();
|
this._view.sidebarControl.enableForm();
|
||||||
}, errorMessage => {
|
}, error => {
|
||||||
this._view.sidebarControl.showError(errorMessage);
|
this._view.sidebarControl.showError(error.message);
|
||||||
this._view.sidebarControl.enableForm();
|
this._view.sidebarControl.enableForm();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -135,8 +135,8 @@ class PostMainController extends BasePostController {
|
||||||
misc.disableExitConfirmation();
|
misc.disableExitConfirmation();
|
||||||
const ctx = router.show('/posts');
|
const ctx = router.show('/posts');
|
||||||
ctx.controller.showSuccess('Post deleted.');
|
ctx.controller.showSuccess('Post deleted.');
|
||||||
}, errorMessage => {
|
}, error => {
|
||||||
this._view.sidebarControl.showError(errorMessage);
|
this._view.sidebarControl.showError(error.message);
|
||||||
this._view.sidebarControl.enableForm();
|
this._view.sidebarControl.enableForm();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -168,8 +168,8 @@ class PostMainController extends BasePostController {
|
||||||
this._view.sidebarControl.showSuccess('Post saved.');
|
this._view.sidebarControl.showSuccess('Post saved.');
|
||||||
this._view.sidebarControl.enableForm();
|
this._view.sidebarControl.enableForm();
|
||||||
misc.disableExitConfirmation();
|
misc.disableExitConfirmation();
|
||||||
}, errorMessage => {
|
}, error => {
|
||||||
this._view.sidebarControl.showError(errorMessage);
|
this._view.sidebarControl.showError(error.message);
|
||||||
this._view.sidebarControl.enableForm();
|
this._view.sidebarControl.enableForm();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -192,8 +192,8 @@ class PostMainController extends BasePostController {
|
||||||
this._view.commentControl.exitEditMode();
|
this._view.commentControl.exitEditMode();
|
||||||
this._view.commentControl.enableForm();
|
this._view.commentControl.enableForm();
|
||||||
misc.disableExitConfirmation();
|
misc.disableExitConfirmation();
|
||||||
}, errorMessage => {
|
}, error => {
|
||||||
this._view.commentControl.showError(errorMessage);
|
this._view.commentControl.showError(error.message);
|
||||||
this._view.commentControl.enableForm();
|
this._view.commentControl.enableForm();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -202,24 +202,20 @@ class PostMainController extends BasePostController {
|
||||||
// TODO: disable form
|
// TODO: disable form
|
||||||
e.detail.comment.text = e.detail.text;
|
e.detail.comment.text = e.detail.text;
|
||||||
e.detail.comment.save()
|
e.detail.comment.save()
|
||||||
.catch(errorMessage => {
|
.catch(error => {
|
||||||
e.detail.target.showError(errorMessage);
|
e.detail.target.showError(error.message);
|
||||||
// TODO: enable form
|
// TODO: enable form
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_evtScoreComment(e) {
|
_evtScoreComment(e) {
|
||||||
e.detail.comment.setScore(e.detail.score)
|
e.detail.comment.setScore(e.detail.score)
|
||||||
.catch(errorMessage => {
|
.catch(error => window.alert(error.message));
|
||||||
window.alert(errorMessage);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_evtDeleteComment(e) {
|
_evtDeleteComment(e) {
|
||||||
e.detail.comment.delete()
|
e.detail.comment.delete()
|
||||||
.catch(errorMessage => {
|
.catch(error => window.alert(error.message));
|
||||||
window.alert(errorMessage);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_evtScorePost(e) {
|
_evtScorePost(e) {
|
||||||
|
@ -227,9 +223,7 @@ class PostMainController extends BasePostController {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
e.detail.post.setScore(e.detail.score)
|
e.detail.post.setScore(e.detail.score)
|
||||||
.catch(errorMessage => {
|
.catch(error => window.alert(error.message));
|
||||||
window.alert(errorMessage);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_evtFavoritePost(e) {
|
_evtFavoritePost(e) {
|
||||||
|
@ -237,9 +231,7 @@ class PostMainController extends BasePostController {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
e.detail.post.addToFavorites()
|
e.detail.post.addToFavorites()
|
||||||
.catch(errorMessage => {
|
.catch(error => window.alert(error.message));
|
||||||
window.alert(errorMessage);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_evtUnfavoritePost(e) {
|
_evtUnfavoritePost(e) {
|
||||||
|
@ -247,9 +239,7 @@ class PostMainController extends BasePostController {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
e.detail.post.removeFromFavorites()
|
e.detail.post.removeFromFavorites()
|
||||||
.catch(errorMessage => {
|
.catch(error => window.alert(error.message));
|
||||||
window.alert(errorMessage);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,22 +62,23 @@ class PostUploadController {
|
||||||
misc.disableExitConfirmation();
|
misc.disableExitConfirmation();
|
||||||
const ctx = router.show('/posts');
|
const ctx = router.show('/posts');
|
||||||
ctx.controller.showSuccess('Posts uploaded.');
|
ctx.controller.showSuccess('Posts uploaded.');
|
||||||
}, ([errorMessage, uploadable, similarPostResults]) => {
|
}, error => {
|
||||||
if (uploadable) {
|
if (error.uploadable) {
|
||||||
if (similarPostResults) {
|
if (error.similarPosts) {
|
||||||
uploadable.lookalikes = similarPostResults;
|
error.uploadable.lookalikes = error.similarPosts;
|
||||||
this._view.updateUploadable(uploadable);
|
this._view.updateUploadable(error.uploadable);
|
||||||
this._view.showInfo(genericErrorMessage);
|
this._view.showInfo(genericErrorMessage);
|
||||||
this._view.showInfo(errorMessage, uploadable);
|
this._view.showInfo(
|
||||||
|
error.message, error.uploadable);
|
||||||
} else {
|
} else {
|
||||||
this._view.showError(genericErrorMessage);
|
this._view.showError(genericErrorMessage);
|
||||||
this._view.showError(errorMessage, uploadable);
|
this._view.showError(
|
||||||
|
error.message, error.uploadable);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this._view.showError(errorMessage);
|
this._view.showError(error.message);
|
||||||
}
|
}
|
||||||
this._view.enableForm();
|
this._view.enableForm();
|
||||||
return Promise.reject();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,20 +95,21 @@ class PostUploadController {
|
||||||
if (searchResult) {
|
if (searchResult) {
|
||||||
// notify about exact duplicate
|
// notify about exact duplicate
|
||||||
if (searchResult.exactPost && !skipDuplicates) {
|
if (searchResult.exactPost && !skipDuplicates) {
|
||||||
return Promise.reject([
|
let error = new Error('Post already uploaded ' +
|
||||||
`Post already uploaded (@${searchResult.exactPost.id})`,
|
`(@${searchResult.exactPost.id})`);
|
||||||
uploadable,
|
error.uploadable = uploadable;
|
||||||
null]);
|
return Promise.reject(error);
|
||||||
}
|
}
|
||||||
|
|
||||||
// notify about similar posts
|
// notify about similar posts
|
||||||
if (!searchResult.exactPost
|
if (!searchResult.exactPost &&
|
||||||
&& searchResult.similarPosts.length) {
|
searchResult.similarPosts.length) {
|
||||||
return Promise.reject([
|
let error = new Error(
|
||||||
`Found ${searchResult.similarPosts.length} similar ` +
|
`Found ${searchResult.similarPosts.length} similar ` +
|
||||||
'posts.\nYou can resume or discard this upload.',
|
'posts.\nYou can resume or discard this upload.');
|
||||||
uploadable,
|
error.uploadable = uploadable;
|
||||||
searchResult.similarPosts]);
|
error.similarPosts = searchResult.similarPosts;
|
||||||
|
return Promise.reject(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,8 +120,6 @@ class PostUploadController {
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this._view.removeUploadable(uploadable);
|
this._view.removeUploadable(uploadable);
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}, errorMessage => {
|
|
||||||
return Promise.reject([errorMessage, uploadable, null]);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
returnedSavePromise.abort = () => {
|
returnedSavePromise.abort = () => {
|
||||||
|
@ -128,8 +128,6 @@ class PostUploadController {
|
||||||
|
|
||||||
this._lastCancellablePromise = returnedSavePromise;
|
this._lastCancellablePromise = returnedSavePromise;
|
||||||
return returnedSavePromise;
|
return returnedSavePromise;
|
||||||
}, errorMessage => {
|
|
||||||
return Promise.reject([errorMessage, uploadable, null]);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,9 +29,9 @@ class TagCategoriesController {
|
||||||
canSetDefault: api.hasPrivilege('tagCategories:setDefault'),
|
canSetDefault: api.hasPrivilege('tagCategories:setDefault'),
|
||||||
});
|
});
|
||||||
this._view.addEventListener('submit', e => this._evtSubmit(e));
|
this._view.addEventListener('submit', e => this._evtSubmit(e));
|
||||||
}, errorMessage => {
|
}, error => {
|
||||||
this._view = new EmptyView();
|
this._view = new EmptyView();
|
||||||
this._view.showError(errorMessage);
|
this._view.showError(error.message);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,9 +43,9 @@ class TagCategoriesController {
|
||||||
tags.refreshExport();
|
tags.refreshExport();
|
||||||
this._view.enableForm();
|
this._view.enableForm();
|
||||||
this._view.showSuccess('Changes saved.');
|
this._view.showSuccess('Changes saved.');
|
||||||
}, errorMessage => {
|
}, error => {
|
||||||
this._view.enableForm();
|
this._view.enableForm();
|
||||||
this._view.showError(errorMessage);
|
this._view.showError(error.message);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,9 +47,9 @@ class TagController {
|
||||||
this._view.addEventListener('submit', e => this._evtUpdate(e));
|
this._view.addEventListener('submit', e => this._evtUpdate(e));
|
||||||
this._view.addEventListener('merge', e => this._evtMerge(e));
|
this._view.addEventListener('merge', e => this._evtMerge(e));
|
||||||
this._view.addEventListener('delete', e => this._evtDelete(e));
|
this._view.addEventListener('delete', e => this._evtDelete(e));
|
||||||
}, errorMessage => {
|
}, error => {
|
||||||
this._view = new EmptyView();
|
this._view = new EmptyView();
|
||||||
this._view.showError(errorMessage);
|
this._view.showError(error.message);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,8 +86,8 @@ class TagController {
|
||||||
e.detail.tag.save().then(() => {
|
e.detail.tag.save().then(() => {
|
||||||
this._view.showSuccess('Tag saved.');
|
this._view.showSuccess('Tag saved.');
|
||||||
this._view.enableForm();
|
this._view.enableForm();
|
||||||
}, errorMessage => {
|
}, error => {
|
||||||
this._view.showError(errorMessage);
|
this._view.showError(error.message);
|
||||||
this._view.enableForm();
|
this._view.enableForm();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -100,8 +100,8 @@ class TagController {
|
||||||
this._view.enableForm();
|
this._view.enableForm();
|
||||||
router.replace(
|
router.replace(
|
||||||
'/tag/' + e.detail.targetTagName + '/merge', null, false);
|
'/tag/' + e.detail.targetTagName + '/merge', null, false);
|
||||||
}, errorMessage => {
|
}, error => {
|
||||||
this._view.showError(errorMessage);
|
this._view.showError(error.message);
|
||||||
this._view.enableForm();
|
this._view.enableForm();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -113,8 +113,8 @@ class TagController {
|
||||||
.then(() => {
|
.then(() => {
|
||||||
const ctx = router.show('/tags/');
|
const ctx = router.show('/tags/');
|
||||||
ctx.controller.showSuccess('Tag deleted.');
|
ctx.controller.showSuccess('Tag deleted.');
|
||||||
}, errorMessage => {
|
}, error => {
|
||||||
this._view.showError(errorMessage);
|
this._view.showError(error.message);
|
||||||
this._view.enableForm();
|
this._view.enableForm();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -63,9 +63,9 @@ class UserController {
|
||||||
this._view.addEventListener('change', e => this._evtChange(e));
|
this._view.addEventListener('change', e => this._evtChange(e));
|
||||||
this._view.addEventListener('submit', e => this._evtUpdate(e));
|
this._view.addEventListener('submit', e => this._evtUpdate(e));
|
||||||
this._view.addEventListener('delete', e => this._evtDelete(e));
|
this._view.addEventListener('delete', e => this._evtDelete(e));
|
||||||
}, errorMessage => {
|
}, error => {
|
||||||
this._view = new EmptyView();
|
this._view = new EmptyView();
|
||||||
this._view.showError(errorMessage);
|
this._view.showError(error.message);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -115,13 +115,11 @@ class UserController {
|
||||||
e.detail.password || api.userPassword,
|
e.detail.password || api.userPassword,
|
||||||
false) :
|
false) :
|
||||||
Promise.resolve();
|
Promise.resolve();
|
||||||
}, errorMessage => {
|
|
||||||
return Promise.reject(errorMessage);
|
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
this._view.showSuccess('Settings updated.');
|
this._view.showSuccess('Settings updated.');
|
||||||
this._view.enableForm();
|
this._view.enableForm();
|
||||||
}, errorMessage => {
|
}, error => {
|
||||||
this._view.showError(errorMessage);
|
this._view.showError(error.message);
|
||||||
this._view.enableForm();
|
this._view.enableForm();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -143,8 +141,8 @@ class UserController {
|
||||||
const ctx = router.show('/');
|
const ctx = router.show('/');
|
||||||
ctx.controller.showSuccess('Account deleted.');
|
ctx.controller.showSuccess('Account deleted.');
|
||||||
}
|
}
|
||||||
}, errorMessage => {
|
}, error => {
|
||||||
this._view.showError(errorMessage);
|
this._view.showError(error.message);
|
||||||
this._view.enableForm();
|
this._view.enableForm();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,13 +31,11 @@ class UserRegistrationController {
|
||||||
user.save().then(() => {
|
user.save().then(() => {
|
||||||
api.forget();
|
api.forget();
|
||||||
return api.login(e.detail.name, e.detail.password, false);
|
return api.login(e.detail.name, e.detail.password, false);
|
||||||
}, errorMessage => {
|
|
||||||
return Promise.reject(errorMessage);
|
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
const ctx = router.show('/');
|
const ctx = router.show('/');
|
||||||
ctx.controller.showSuccess('Welcome aboard!');
|
ctx.controller.showSuccess('Welcome aboard!');
|
||||||
}, errorMessage => {
|
}, error => {
|
||||||
this._view.showError(errorMessage);
|
this._view.showError(error.message);
|
||||||
this._view.enableForm();
|
this._view.enableForm();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ const api = require('./api.js');
|
||||||
tags.refreshExport(); // we don't care about errors
|
tags.refreshExport(); // we don't care about errors
|
||||||
api.loginFromCookies().then(() => {
|
api.loginFromCookies().then(() => {
|
||||||
router.start();
|
router.start();
|
||||||
}, errorMessage => {
|
}, error => {
|
||||||
if (window.location.href.indexOf('login') !== -1) {
|
if (window.location.href.indexOf('login') !== -1) {
|
||||||
api.forget();
|
api.forget();
|
||||||
router.start();
|
router.start();
|
||||||
|
@ -66,6 +66,6 @@ api.loginFromCookies().then(() => {
|
||||||
const ctx = router.start('/');
|
const ctx = router.start('/');
|
||||||
ctx.controller.showError(
|
ctx.controller.showError(
|
||||||
'An error happened while trying to log you in: ' +
|
'An error happened while trying to log you in: ' +
|
||||||
errorMessage);
|
error.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -50,8 +50,6 @@ class Comment extends events.EventTarget {
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}, response => {
|
|
||||||
return Promise.reject(response.description);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,8 +64,6 @@ class Comment extends events.EventTarget {
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}, response => {
|
|
||||||
return Promise.reject(response.description);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,8 +77,6 @@ class Comment extends events.EventTarget {
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}, response => {
|
|
||||||
return Promise.reject(response.description);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,6 @@ class Info {
|
||||||
Post.fromResponse(response.featuredPost) :
|
Post.fromResponse(response.featuredPost) :
|
||||||
undefined
|
undefined
|
||||||
}));
|
}));
|
||||||
}, response => {
|
|
||||||
return Promise.reject(response.description);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,8 +79,6 @@ class Post extends events.EventTarget {
|
||||||
item.post = Post.fromResponse(item.post);
|
item.post = Post.fromResponse(item.post);
|
||||||
}
|
}
|
||||||
return Promise.resolve(response);
|
return Promise.resolve(response);
|
||||||
}, response => {
|
|
||||||
return Promise.reject(response.description);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
returnedPromise.abort = () => {
|
returnedPromise.abort = () => {
|
||||||
|
@ -94,8 +92,6 @@ class Post extends events.EventTarget {
|
||||||
return api.get('/post/' + id)
|
return api.get('/post/' + id)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
return Promise.resolve(Post.fromResponse(response));
|
return Promise.resolve(Post.fromResponse(response));
|
||||||
}, response => {
|
|
||||||
return Promise.reject(response.description);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,12 +169,13 @@ class Post extends events.EventTarget {
|
||||||
new CustomEvent('changeThumbnail', {detail: {post: this}}));
|
new CustomEvent('changeThumbnail', {detail: {post: this}}));
|
||||||
}
|
}
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}, response => {
|
}, error => {
|
||||||
if (response.name === 'PostAlreadyUploadedError') {
|
if (error.response &&
|
||||||
return Promise.reject(
|
error.response.name === 'PostAlreadyUploadedError') {
|
||||||
`Post already uploaded (@${response.otherPostId})`);
|
error.message =
|
||||||
|
`Post already uploaded (@${error.response.otherPostId})`;
|
||||||
}
|
}
|
||||||
return Promise.reject(response.description);
|
return Promise.reject(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
returnedPromise.abort = () => {
|
returnedPromise.abort = () => {
|
||||||
|
@ -192,8 +189,6 @@ class Post extends events.EventTarget {
|
||||||
return api.post('/featured-post', {id: this._id})
|
return api.post('/featured-post', {id: this._id})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}, response => {
|
|
||||||
return Promise.reject(response.description);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,8 +201,6 @@ class Post extends events.EventTarget {
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}, response => {
|
|
||||||
return Promise.reject(response.description);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,8 +214,6 @@ class Post extends events.EventTarget {
|
||||||
mergeTo: targetId,
|
mergeTo: targetId,
|
||||||
replaceContent: useOldContent,
|
replaceContent: useOldContent,
|
||||||
});
|
});
|
||||||
}, response => {
|
|
||||||
return Promise.reject(response);
|
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
this._updateFromResponse(response);
|
this._updateFromResponse(response);
|
||||||
this.dispatchEvent(new CustomEvent('change', {
|
this.dispatchEvent(new CustomEvent('change', {
|
||||||
|
@ -231,8 +222,6 @@ class Post extends events.EventTarget {
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}, response => {
|
|
||||||
return Promise.reject(response.description);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,8 +243,6 @@ class Post extends events.EventTarget {
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}, response => {
|
|
||||||
return Promise.reject(response.description);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,8 +264,6 @@ class Post extends events.EventTarget {
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}, response => {
|
|
||||||
return Promise.reject(response.description);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,8 +285,6 @@ class Post extends events.EventTarget {
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}, response => {
|
|
||||||
return Promise.reject(response.description);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,12 +9,7 @@ class PostList extends AbstractList {
|
||||||
const url =
|
const url =
|
||||||
`/post/${id}/around?fields=id` +
|
`/post/${id}/around?fields=id` +
|
||||||
`&query=${encodeURIComponent(searchQuery)}`;
|
`&query=${encodeURIComponent(searchQuery)}`;
|
||||||
return api.get(url)
|
return api.get(url);
|
||||||
.then(response => {
|
|
||||||
return Promise.resolve(response);
|
|
||||||
}).catch(response => {
|
|
||||||
return Promise.reject(response.description);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static search(text, page, pageSize, fields) {
|
static search(text, page, pageSize, fields) {
|
||||||
|
|
|
@ -36,8 +36,6 @@ class Tag extends events.EventTarget {
|
||||||
return api.get('/tag/' + encodeURIComponent(name))
|
return api.get('/tag/' + encodeURIComponent(name))
|
||||||
.then(response => {
|
.then(response => {
|
||||||
return Promise.resolve(Tag.fromResponse(response));
|
return Promise.resolve(Tag.fromResponse(response));
|
||||||
}, response => {
|
|
||||||
return Promise.reject(response.description);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,8 +71,6 @@ class Tag extends events.EventTarget {
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}, response => {
|
|
||||||
return Promise.reject(response.description);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,8 +83,6 @@ class Tag extends events.EventTarget {
|
||||||
mergeToVersion: response.version,
|
mergeToVersion: response.version,
|
||||||
mergeTo: targetName,
|
mergeTo: targetName,
|
||||||
});
|
});
|
||||||
}, response => {
|
|
||||||
return Promise.reject(response);
|
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
this._updateFromResponse(response);
|
this._updateFromResponse(response);
|
||||||
this.dispatchEvent(new CustomEvent('change', {
|
this.dispatchEvent(new CustomEvent('change', {
|
||||||
|
@ -97,8 +91,6 @@ class Tag extends events.EventTarget {
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}, response => {
|
|
||||||
return Promise.reject(response.description);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,8 +105,6 @@ class Tag extends events.EventTarget {
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}, response => {
|
|
||||||
return Promise.reject(response.description);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,8 +58,6 @@ class TagCategory extends events.EventTarget {
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}, response => {
|
|
||||||
return Promise.reject(response.description);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,8 +72,6 @@ class TagCategory extends events.EventTarget {
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}, response => {
|
|
||||||
return Promise.reject(response.description);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,9 +61,6 @@ class TagCategoryList extends AbstractList {
|
||||||
.then(response => {
|
.then(response => {
|
||||||
this._deletedCategories = [];
|
this._deletedCategories = [];
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}, errorMessage => {
|
|
||||||
return Promise.reject(
|
|
||||||
errorMessage.description || errorMessage);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,8 +43,6 @@ class User extends events.EventTarget {
|
||||||
return api.get('/user/' + encodeURIComponent(name))
|
return api.get('/user/' + encodeURIComponent(name))
|
||||||
.then(response => {
|
.then(response => {
|
||||||
return Promise.resolve(User.fromResponse(response));
|
return Promise.resolve(User.fromResponse(response));
|
||||||
}, response => {
|
|
||||||
return Promise.reject(response.description);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,8 +87,6 @@ class User extends events.EventTarget {
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}, response => {
|
|
||||||
return Promise.reject(response.description);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,8 +101,6 @@ class User extends events.EventTarget {
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}, response => {
|
|
||||||
return Promise.reject(response.description);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -114,8 +114,8 @@ class EndlessPageView {
|
||||||
this._working--;
|
this._working--;
|
||||||
resolve(pageNode);
|
resolve(pageNode);
|
||||||
});
|
});
|
||||||
}, response => {
|
}, error => {
|
||||||
this.showError(response.description);
|
this.showError(error.message);
|
||||||
this._working--;
|
this._working--;
|
||||||
reject();
|
reject();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue