summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--web-ui/app/js/mail_view/data/mail_sender.js16
-rw-r--r--web-ui/test/spec/mail_view/data/mail_sender.spec.js26
2 files changed, 39 insertions, 3 deletions
diff --git a/web-ui/app/js/mail_view/data/mail_sender.js b/web-ui/app/js/mail_view/data/mail_sender.js
index 6d572e77..7ada0d16 100644
--- a/web-ui/app/js/mail_view/data/mail_sender.js
+++ b/web-ui/app/js/mail_view/data/mail_sender.js
@@ -39,9 +39,19 @@ define(
};
}
- function failure(on) {
+ function failure(on, context) {
return function(xhr, status, error) {
- on.trigger(events.ui.userAlerts.displayMessage, {message: 'Ops! something went wrong, try again later.'});
+ var contextMessage = '';
+
+ if (context) {
+ contextMessage = context + ': ';
+ }
+
+ if (xhr.responseJSON.message) {
+ on.trigger(document, events.ui.userAlerts.displayMessage, {message: contextMessage + xhr.responseJSON.message});
+ } else {
+ on.trigger(document, events.ui.userAlerts.displayMessage, {message: 'Ops! something went wrong, try again later.'});
+ }
};
}
@@ -56,7 +66,7 @@ define(
contentType: 'application/json; charset=utf-8',
data: JSON.stringify(data)
}).done(successSendMail(this))
- .fail(failure(this));
+ .fail(failure(this, 'Error sending mail'));
};
this.saveMail = function(mail) {
diff --git a/web-ui/test/spec/mail_view/data/mail_sender.spec.js b/web-ui/test/spec/mail_view/data/mail_sender.spec.js
index d1df2f47..f5a0dd92 100644
--- a/web-ui/test/spec/mail_view/data/mail_sender.spec.js
+++ b/web-ui/test/spec/mail_view/data/mail_sender.spec.js
@@ -48,4 +48,30 @@ describeComponent('mail_view/data/mail_sender', function () {
expect(JSON.parse($.ajax.mostRecentCall.args[1].data).header).toEqual(mail.header);
expect(JSON.parse($.ajax.mostRecentCall.args[1].data).body).toEqual(mail.body);
});
+
+ it('displays generic error message when sending an email fails in the service', function () {
+ var deferred;
+ deferred = $.Deferred();
+ deferred.reject({responseJSON: {}}, 500, 'Internal Server Error');
+
+ var messageEvent = spyOnEvent(document, Pixelated.events.ui.userAlerts.displayMessage);
+ spyOn($, 'ajax').andReturn(deferred);
+
+ this.component.trigger(Pixelated.events.mail.send, mail);
+
+ expect(messageEvent).toHaveBeenTriggeredOnAndWith(document, {message: 'Ops! something went wrong, try again later.'});
+ });
+
+ it('displays error message returned by the service when sending an email fails in the service', function () {
+ var deferred;
+ deferred = $.Deferred();
+ deferred.reject({responseJSON: {message: 'test: error message'}}, 422, 'Unprocessable Entity');
+
+ var messageEvent = spyOnEvent(document, Pixelated.events.ui.userAlerts.displayMessage);
+ spyOn($, 'ajax').andReturn(deferred);
+
+ this.component.trigger(Pixelated.events.mail.send, mail);
+
+ expect(messageEvent).toHaveBeenTriggeredOnAndWith(document, {message: 'Error sending mail: test: error message'});
+ });
});