Handle invalid parameters and missing bounced emails

This commit is contained in:
Rafael dos Santos Silva 2017-03-02 20:37:28 -03:00
parent 5296f00c28
commit aac4a4ed94
2 changed files with 21 additions and 7 deletions

View File

@ -2,6 +2,7 @@ import ModalFunctionality from 'discourse/mixins/modal-functionality';
import IncomingEmail from 'admin/models/incoming-email'; import IncomingEmail from 'admin/models/incoming-email';
import computed from 'ember-addons/ember-computed-decorators'; import computed from 'ember-addons/ember-computed-decorators';
import { longDate } from 'discourse/lib/formatter'; import { longDate } from 'discourse/lib/formatter';
import { popupAjaxError } from 'discourse/lib/ajax-error';
export default Ember.Controller.extend(ModalFunctionality, { export default Ember.Controller.extend(ModalFunctionality, {
@ -15,7 +16,12 @@ export default Ember.Controller.extend(ModalFunctionality, {
}, },
loadFromBounced(id) { loadFromBounced(id) {
return IncomingEmail.findByBounced(id).then(result => this.set("model", result)); return IncomingEmail.findByBounced(id)
.then(result => this.set("model", result))
.catch(error => {
this.send("closeModal");
popupAjaxError(error);
});
} }
}); });

View File

@ -91,13 +91,21 @@ class Admin::EmailController < Admin::AdminController
def incoming_from_bounced def incoming_from_bounced
params.require(:id) params.require(:id)
bounced = EmailLog.find(params[:id].to_i) begin
bounced = EmailLog.find_by(id: params[:id].to_i)
raise Discourse::InvalidParameters if bounced.nil?
email_local_part, email_domain = SiteSetting.notification_email.split('@') email_local_part, email_domain = SiteSetting.notification_email.split('@')
bounced_to_address = "#{email_local_part}+verp-#{bounced.bounce_key}@#{email_domain}" bounced_to_address = "#{email_local_part}+verp-#{bounced.bounce_key}@#{email_domain}"
incoming_email = IncomingEmail.find_by(to_addresses: bounced_to_address) incoming_email = IncomingEmail.find_by(to_addresses: bounced_to_address)
raise Discourse::NotFound if incoming_email.nil?
serializer = IncomingEmailDetailsSerializer.new(incoming_email, root: false) serializer = IncomingEmailDetailsSerializer.new(incoming_email, root: false)
render_json_dump(serializer) render_json_dump(serializer)
rescue => e
render json: {errors: [e.message]}, status: 404
end
end end
private private