}
export function parseError (error) {
+ const DEFAULT_MESSAGE = translate('default_error_message');
+
try {
- return error.response.json().then(r => {
- return r.errors.map(error => error.msg).join('. ');
- });
+ return error.response.json()
+ .then(r => r.errors.map(error => error.msg).join('. '))
+ .catch(() => DEFAULT_MESSAGE);
} catch (ex) {
- return Promise.resolve(translate('default_error_message'));
+ return Promise.resolve(DEFAULT_MESSAGE);
}
}
*/
import ModalForm from '../../../../components/common/modal-form';
import Template from './CreationModalTemplate.hbs';
+import { parseError } from '../../../code/utils';
export default ModalForm.extend({
template: Template,
const url = this.$('#create-link-url').val();
this.options.onCreate(name, url)
- .then(() => {
- this.destroy();
- })
- .catch(function (e) {
- e.response.json().then(r => {
- this.showErrors(r.errors, r.warnings);
- this.enableForm();
- });
+ .then(() => this.destroy())
+ .catch(e => {
+ parseError(e).then(msg => this.showSingleError(msg));
+ this.enableForm();
});
}
});
import ModalForm from '../../../../components/common/modal-form';
import Template from './DeletionModalTemplate.hbs';
import { deleteLink } from '../../../../api/projectLinks';
+import { parseError } from '../../../code/utils';
export default ModalForm.extend({
template: Template,
this.trigger('done');
this.destroy();
})
- .catch(function (e) {
- e.response.json().then(r => {
- this.showErrors(r.errors, r.warnings);
- this.enableForm();
- });
+ .catch(e => {
+ parseError(e).then(msg => this.showSingleError(msg));
+ this.enableForm();
});
},
this.ui.messagesContainer.scrollParent().scrollTop(0);
},
+ showSingleError (msg) {
+ this.showErrors([{ msg }], []);
+ },
+
disableForm () {
const form = this.$('form');
this.disabledFields = form.find(':input:not(:disabled)');