From b947fdf12859cefdba08c51e9c332e924e670e11 Mon Sep 17 00:00:00 2001 From: Maksym Koshovyi Date: Sun, 23 Jan 2022 11:44:36 +0200 Subject: [PATCH] SendGridStatusCode --- src/SendGrid/Helpers/Errors/ErrorHandler.cs | 2 +- .../Errors/Model/SendGridErrorResponse.cs | 5 +- .../Errors/Model/SendGridStatusCode.cs | 105 ++++++++++++++++++ tests/SendGrid.Tests/Integration.cs | 2 +- 4 files changed, 110 insertions(+), 4 deletions(-) create mode 100644 src/SendGrid/Helpers/Errors/Model/SendGridStatusCode.cs diff --git a/src/SendGrid/Helpers/Errors/ErrorHandler.cs b/src/SendGrid/Helpers/Errors/ErrorHandler.cs index bb1204681..07e5df045 100644 --- a/src/SendGrid/Helpers/Errors/ErrorHandler.cs +++ b/src/SendGrid/Helpers/Errors/ErrorHandler.cs @@ -87,7 +87,7 @@ public static async Task ThrowException(HttpResponseMessage message) /// Return string with the error Status Code and the Message private static async Task GetErrorMessage(HttpResponseMessage message) { - var errorStatusCode = (int)message.StatusCode; + var errorStatusCode = (SendGridStatusCode)message.StatusCode; var errorReasonPhrase = message.ReasonPhrase; string errorValue = null; diff --git a/src/SendGrid/Helpers/Errors/Model/SendGridErrorResponse.cs b/src/SendGrid/Helpers/Errors/Model/SendGridErrorResponse.cs index 1f55189fa..af55b7121 100644 --- a/src/SendGrid/Helpers/Errors/Model/SendGridErrorResponse.cs +++ b/src/SendGrid/Helpers/Errors/Model/SendGridErrorResponse.cs @@ -6,9 +6,10 @@ public class SendGridErrorResponse { /// - /// Gets or sets the error Status Code + /// Gets or sets the error Status Code.
+ /// Might be any , not just ones in . ///
- public int ErrorHttpStatusCode { get; set; } + public SendGridStatusCode ErrorHttpStatusCode { get; set; } /// /// Gets or sets the error Reason Phrase diff --git a/src/SendGrid/Helpers/Errors/Model/SendGridStatusCode.cs b/src/SendGrid/Helpers/Errors/Model/SendGridStatusCode.cs new file mode 100644 index 000000000..4603efd42 --- /dev/null +++ b/src/SendGrid/Helpers/Errors/Model/SendGridStatusCode.cs @@ -0,0 +1,105 @@ +namespace SendGrid.Helpers.Errors.Model +{ + /// + /// Each SMTP call you make returns a response. + /// 200 responses are usually success responses, and 400 responses are usually deferrals. + /// SendGrid continues to retry resending 400 messages for up to 72 hours. + /// 500 responses are hard failures that are not retried by our servers. + /// + /// + /// . + /// + public enum SendGridStatusCode + { + /// + /// Your mail has been successfully queued! + /// This response indicates that the recipient server has accepted the message. + /// + QueuedForDelivery = 250, + + /// + /// This means the "from" address does not match a verified Sender Identity. + /// Mail cannot be sent until this error is resolved. + /// + /// + /// To learn how to resolve this error, see our Sender Identity requirements. + /// + InvalidFromAddress = 403, + + /// + /// Messages are temporarily deferred because of recipient server policy - often it's because of too many messages or connections in too short of a timeframe. + /// + /// + /// We continue to retry deferred messages for up to 72 hours. + /// Consider temporarily sending less messages to a domain that is returning this code because this could further delay your messages currently being tried. + /// + MessagesDeferred = 421, + + /// + /// The message failed because the recipient's mailbox was unavailable, perhaps because it was locked or was not routable at the time. + /// + /// + /// We continue to retry messages for up to 72 hours. + /// Consider temporarily sending less messages to a domain that is returning this code because this could further delay your messages currently being tried. + /// + MailboxUnavailable = 450, + + /// + /// There is a credit limit of emails per day enforced in error. + /// + /// + /// Contact support to remove that limit. + /// + MaximumCreditsExceeded = 451, + + /// + /// The message has been deferred due to insufficient system storage. + /// + /// + /// We continue to retry messages for up to 72 hours. + /// + TooManyRecipientsThisHour = 452, + + /// + /// The user’s mailbox was unavailable. + /// Usually because it could not be found, or because of incoming policy reasons. + /// + /// + /// Remove these address from your list - it is likely a fake, or it was mistyped. + /// + InvalidMailbox = 550, + + /// + /// The intended mailbox does not exist on this recipient server. + /// + /// + /// Remove these addresses from your list. + /// + UserDoesNotExist = 551, + + /// + /// The recipients mailbox has exceeded its storage limits. + /// + /// + /// We don't resend messages with this error code because this is usually a sign this is an abandoned email. + /// + MailboxIsFull = 552, + + /// + /// The message was refused because the mailbox name is either malformed or does not exist. + /// + /// + /// Remove these addresses from your list. + /// + InvalidUser = 553, + + /// + /// This is a default response that can be caused by a lot of issues. + /// + /// + /// There is often a human readable portion of this error that gives more detailed information, but if not, + /// remove these addresses from your list. + /// + MailRefused = 554, + } +} diff --git a/tests/SendGrid.Tests/Integration.cs b/tests/SendGrid.Tests/Integration.cs index c1f915919..0ecb4b465 100644 --- a/tests/SendGrid.Tests/Integration.cs +++ b/tests/SendGrid.Tests/Integration.cs @@ -6059,7 +6059,7 @@ public async void TestHttpErrorAsException() var errorResponseExpected = new SendGridErrorResponse { - ErrorHttpStatusCode = 503, + ErrorHttpStatusCode = (SendGridStatusCode)503, ErrorReasonPhrase = "Service Unavailable", SendGridErrorMessage = "error message", FieldWithError = "field value",