mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-01-06 08:08:10 +08:00
fix(402s): Handling of Message Rejected, error messages with more detail
This commit is contained in:
parent
038f348281
commit
73ddd39cb2
3 changed files with 56 additions and 2 deletions
|
@ -214,6 +214,51 @@ describe "SendDraftTask", ->
|
|||
expect(status[1]).toBe thrownError
|
||||
expect(Actions.draftSendingFailed).toHaveBeenCalled()
|
||||
|
||||
it "presents helpful error messages for 402 errors (security blocked)", ->
|
||||
thrownError = new APIError(statusCode: 402, body: {
|
||||
"message": "Message content rejected for security reasons",
|
||||
"server_error": "552 : 5.7.0 This message was blocked because its content presents a potential\n5.7.0 security issue. Please visit\n5.7.0 https://support.google.com/mail/answer/6590 to review our message\n5.7.0 content and attachment content guidelines. fk9sm21147314pad.9 - gsmtp",
|
||||
"type": "api_error"
|
||||
})
|
||||
|
||||
expectedMessage =
|
||||
"""
|
||||
Sorry, this message could not be sent because it was rejected by your mail provider. (Message content rejected for security reasons)
|
||||
|
||||
552 : 5.7.0 This message was blocked because its content presents a potential
|
||||
5.7.0 security issue. Please visit
|
||||
5.7.0 https://support.google.com/mail/answer/6590 to review our message
|
||||
5.7.0 content and attachment content guidelines. fk9sm21147314pad.9 - gsmtp
|
||||
"""
|
||||
|
||||
spyOn(NylasEnv, "reportError")
|
||||
spyOn(NylasAPI, 'makeRequest').andCallFake (options) =>
|
||||
Promise.reject(thrownError)
|
||||
waitsForPromise => @task.performRemote().then (status) =>
|
||||
expect(status[0]).toBe Task.Status.Failed
|
||||
expect(status[1]).toBe thrownError
|
||||
expect(Actions.draftSendingFailed).toHaveBeenCalled()
|
||||
expect(Actions.draftSendingFailed.calls[0].args[0].errorMessage).toEqual(expectedMessage)
|
||||
|
||||
it "presents helpful error messages for 402 errors (recipient failed)", ->
|
||||
thrownError = new APIError(statusCode: 402, body: {
|
||||
"message": "Sending to at least one recipient failed.",
|
||||
"server_error": "<<Don't know what this looks like >>",
|
||||
"type": "api_error"
|
||||
})
|
||||
|
||||
expectedMessage = "This message could not be delivered to at least one recipient. (Note: other recipients may have received this message - you should check Sent Mail before re-sending this message.)"
|
||||
|
||||
spyOn(NylasEnv, "reportError")
|
||||
spyOn(NylasAPI, 'makeRequest').andCallFake (options) =>
|
||||
Promise.reject(thrownError)
|
||||
waitsForPromise => @task.performRemote().then (status) =>
|
||||
expect(status[0]).toBe Task.Status.Failed
|
||||
expect(status[1]).toBe thrownError
|
||||
expect(Actions.draftSendingFailed).toHaveBeenCalled()
|
||||
expect(Actions.draftSendingFailed.calls[0].args[0].errorMessage).toEqual(expectedMessage)
|
||||
|
||||
|
||||
it "retries on timeouts", ->
|
||||
thrownError = new APIError(statusCode: NylasAPI.TimeoutErrorCode, body: "err")
|
||||
spyOn(NylasAPI, 'makeRequest').andCallFake (options) =>
|
||||
|
|
|
@ -11,7 +11,7 @@ async = require 'async'
|
|||
# A 0 code is when an error returns without a status code. These are
|
||||
# things like "ESOCKETTIMEDOUT"
|
||||
TimeoutErrorCode = 0
|
||||
PermanentErrorCodes = [400, 401, 403, 404, 405, 500]
|
||||
PermanentErrorCodes = [400, 401, 402, 403, 404, 405, 500]
|
||||
CancelledErrorCode = -123
|
||||
SampleTemporaryErrorCode = 504
|
||||
|
||||
|
|
|
@ -211,9 +211,18 @@ class SendDraftTask extends Task
|
|||
if err instanceof APIError and not (err.statusCode in NylasAPI.PermanentErrorCodes)
|
||||
return Promise.resolve(Task.Status.Retry)
|
||||
else
|
||||
message = "Sorry, this message could not be sent. Please try again, and make sure your message is addressed correctly and is not too large."
|
||||
if err.statusCode is 402 and err.body.message
|
||||
if err.body.message.indexOf('at least one recipient') isnt -1
|
||||
message = "This message could not be delivered to at least one recipient. (Note: other recipients may have received this message - you should check Sent Mail before re-sending this message.)"
|
||||
else
|
||||
message = "Sorry, this message could not be sent because it was rejected by your mail provider. (#{err.body.message})"
|
||||
if err.body.server_error
|
||||
message += "\n\n" + err.body.server_error
|
||||
|
||||
Actions.draftSendingFailed
|
||||
threadId: @draft.threadId
|
||||
draftClientId: @draft.clientId,
|
||||
errorMessage: "Your message could not be sent. Check your network connection and try again."
|
||||
errorMessage: message
|
||||
NylasEnv.reportError(err)
|
||||
return Promise.resolve([Task.Status.Failed, err])
|
||||
|
|
Loading…
Reference in a new issue