mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-16 04:08:34 +03:00
ddd41e3b46
refs: https://github.com/TryGhost/Team/issues/510 - We need to display host limit errors if we get them - Host limit errors have a custom message added to them, so we show the original context message
59 lines
1.8 KiB
JavaScript
59 lines
1.8 KiB
JavaScript
import ModalComponent from 'ghost-admin/components/modal-base';
|
|
import {alias} from '@ember/object/computed';
|
|
import {A as emberA} from '@ember/array';
|
|
import {isHostLimitError} from 'ghost-admin/services/ajax';
|
|
import {isInvalidError} from 'ember-ajax/errors';
|
|
import {inject as service} from '@ember/service';
|
|
import {task} from 'ember-concurrency';
|
|
|
|
export default ModalComponent.extend({
|
|
router: service(),
|
|
|
|
errorMessage: null,
|
|
|
|
confirm() {},
|
|
|
|
integration: alias('model'),
|
|
actions: {
|
|
updateName(name) {
|
|
this.integration.set('name', name);
|
|
this.integration.set('hasValidated', emberA());
|
|
this.integration.errors.clear();
|
|
},
|
|
|
|
confirm() {
|
|
return this.createIntegration.perform();
|
|
}
|
|
},
|
|
|
|
createIntegration: task(function* () {
|
|
try {
|
|
let integration = yield this.confirm();
|
|
this.router.transitionTo('integration', integration);
|
|
} catch (error) {
|
|
// TODO: server-side validation errors should be serialized
|
|
// properly so that errors are added to model.errors automatically
|
|
if (error && isInvalidError(error)) {
|
|
let [firstError] = error.payload.errors;
|
|
let {message} = firstError;
|
|
|
|
if (message && message.match(/name/i)) {
|
|
this.get('integration.errors').add('name', message);
|
|
this.get('integration.hasValidated').pushObject('name');
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (isHostLimitError(error)) {
|
|
this.set('errorMessage', error.payload.errors[0].context);
|
|
return;
|
|
}
|
|
|
|
// bubble up to the global error handler
|
|
if (error) {
|
|
throw error;
|
|
}
|
|
}
|
|
}).drop()
|
|
});
|