fix(send) Add better error checking when sending message

Summary:
See title.
I believe this might fix T7559, or at least provide a better error message.

Depends on D3895

Test Plan: manual

Reviewers: spang, mark, halla, evan

Reviewed By: mark, halla, evan

Maniphest Tasks: T7559

Differential Revision: https://phab.nylas.com/D3897
This commit is contained in:
Juan Tejada 2017-02-11 10:40:21 -08:00
parent 1ea9853d12
commit f09eec711c
3 changed files with 13 additions and 3 deletions

View file

@ -425,7 +425,6 @@ class Actions {
static draftDeliveryFailed = ActionScopeGlobal;
static ensureMessageInSentSuccess = ActionScopeGlobal;
static ensureMessageInSentFailed = ActionScopeGlobal;
static sendManyDrafts = ActionScopeWindow;
static ensureDraftSynced = ActionScopeWindow;

View file

@ -56,7 +56,6 @@ export default class EnsureMessageInSentFolderTask extends Task {
})
.catch((err) => {
const errorMessage = `Your message successfully sent; however, we had trouble saving your message, "${this.message.subject}", to your Sent folder.\n\n${err.message}`;
Actions.ensureMessageInSentFailed()
if (err instanceof APIError) {
if (NylasAPI.PermanentErrorCodes.includes(err.statusCode)) {
NylasEnv.showErrorDialog(errorMessage, {showInMainWindow: true, detail: err.stack});

View file

@ -162,6 +162,18 @@ export default class SendDraftTask extends BaseDraftTask {
const errorMessage = `We had trouble sending this message to all recipients. ${failedRecipients} may not have received this email.`;
NylasEnv.showErrorDialog(errorMessage, {showInMainWindow: true});
}
if (!message || !message.id || !message.account_id) {
const errorMessage = `Your message successfully sent; however, we had trouble saving your message, "${message.subject}", to your Sent folder.`;
if (!message) {
throw new Error(`${errorMessage}\n\nError: Did not return message`)
}
if (!message.id) {
throw new Error(`${errorMessage}\n\nError: Returned a message without id`)
}
if (!message.accountId) {
throw new Error(`${errorMessage}\n\nError: Returned a message without accountId`)
}
}
this.message = new Message().fromJSON(message);
this.message.clientId = this.draft.clientId;
@ -199,7 +211,7 @@ export default class SendDraftTask extends BaseDraftTask {
// TODO Handle errors in a cleaner way
if (err instanceof APIError) {
const errorMessage = err.body.message || ''
message = `Sorry, this message could not be sent. Please try again, make sure your message is addressed correctly and is not too large.`;
message = `Sorry, this message could not be sent, please try again.`;
message += `\n\nReason: ${err.message}`
if (errorMessage.includes('Network Error')) {
message = `Sorry, this message could not be sent. There was a network error, please make sure you are online.`