Skip to content

Commit 8af0cc5

Browse files
committed
Improved Exception inheritance chain and consistency
1 parent dffd6d9 commit 8af0cc5

File tree

15 files changed

+76
-35
lines changed

15 files changed

+76
-35
lines changed

PushSharp.Amazon/AdmConnection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public async Task Send (AdmNotification notification)
9595
case HttpStatusCode.BadGateway: //400
9696
case HttpStatusCode.BadRequest: //
9797
if ("InvalidRegistrationId".Equals (reason, StringComparison.InvariantCultureIgnoreCase)) {
98-
throw new DeviceSubscriptonExpiredException {
98+
throw new DeviceSubscriptonExpiredException (notification) {
9999
OldSubscriptionId = regId,
100100
ExpiredAt = DateTime.UtcNow
101101
};

PushSharp.Amazon/Exceptions.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,25 @@ namespace PushSharp.Amazon
55
{
66
public class AdmRateLimitExceededException : NotificationException
77
{
8-
public AdmRateLimitExceededException (string reason, INotification notification)
8+
public AdmRateLimitExceededException (string reason, AdmNotification notification)
99
: base ("Rate Limit Exceeded (" + reason + ")", notification)
1010
{
11+
Notification = notification;
1112
Reason = reason;
1213
}
1314

15+
public new AdmNotification Notification { get; set; }
1416
public string Reason { get; private set; }
1517
}
1618

1719
public class AdmMessageTooLargeException : NotificationException
1820
{
19-
public AdmMessageTooLargeException (INotification notification)
21+
public AdmMessageTooLargeException (AdmNotification notification)
2022
: base ("ADM Message too Large, must be <= 6kb", notification)
2123
{
24+
Notification = notification;
2225
}
26+
27+
public new AdmNotification Notification { get; set; }
2328
}
2429
}
25-

PushSharp.Apple/ApnsConfiguration.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,19 @@ void CheckIsApnsCertificate ()
108108
var commonName = Certificate.SubjectName.Name;
109109

110110
if (!issuerName.Contains ("Apple"))
111-
throw new ApnsConnectionException ("Your Certificate does not appear to be issued by Apple! Please check to ensure you have the correct certificate!");
111+
throw new ArgumentOutOfRangeException ("Your Certificate does not appear to be issued by Apple! Please check to ensure you have the correct certificate!");
112112

113113
if (!Regex.IsMatch (commonName, "Apple.*?Push Services")
114114
&& !commonName.Contains ("Website Push ID:"))
115-
throw new ApnsConnectionException ("Your Certificate is not a valid certificate for connecting to Apple's APNS servers");
115+
throw new ArgumentOutOfRangeException ("Your Certificate is not a valid certificate for connecting to Apple's APNS servers");
116116

117117
if (commonName.Contains ("Development") && ServerEnvironment != ApnsServerEnvironment.Sandbox)
118-
throw new ApnsConnectionException ("You are using a certificate created for connecting only to the Sandbox APNS server but have selected a different server environment to connect to.");
118+
throw new ArgumentOutOfRangeException ("You are using a certificate created for connecting only to the Sandbox APNS server but have selected a different server environment to connect to.");
119119

120120
if (commonName.Contains ("Production") && ServerEnvironment != ApnsServerEnvironment.Production)
121-
throw new ApnsConnectionException ("You are using a certificate created for connecting only to the Production APNS server but have selected a different server environment to connect to.");
121+
throw new ArgumentOutOfRangeException ("You are using a certificate created for connecting only to the Production APNS server but have selected a different server environment to connect to.");
122122
} else {
123-
throw new ApnsConnectionException ("You must provide a Certificate to connect to APNS with!");
123+
throw new ArgumentOutOfRangeException ("You must provide a Certificate to connect to APNS with!");
124124
}
125125
}
126126

PushSharp.Apple/ApnsConnection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ async Task SendBatch ()
160160
} catch (Exception ex) {
161161
Log.Error ("APNS-CLIENT[{0}]: Send Batch Error: Batch ID={1}, Error={2}", id, batchId, ex);
162162
foreach (var n in toSend)
163-
n.CompleteFailed (ex);
163+
n.CompleteFailed (new ApnsNotificationException (ApnsNotificationErrorStatusCode.ConnectionError, n.Notification, ex));
164164
}
165165

166166
Log.Info ("APNS-Client[{0}]: Sent Batch, waiting for possible response...", id);

PushSharp.Apple/Exceptions.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using PushSharp.Core;
23

34
namespace PushSharp.Apple
45
{
@@ -14,24 +15,31 @@ public enum ApnsNotificationErrorStatusCode
1415
InvalidPayloadSize = 7,
1516
InvalidToken = 8,
1617
Shutdown = 10,
18+
ConnectionError = 254,
1719
Unknown = 255
1820
}
1921

20-
public class ApnsNotificationException : Exception
22+
public class ApnsNotificationException : NotificationException
2123
{
2224
public ApnsNotificationException(byte errorStatusCode, ApnsNotification notification)
2325
: this(ToErrorStatusCode(errorStatusCode), notification)
2426
{ }
2527

2628
public ApnsNotificationException (ApnsNotificationErrorStatusCode errorStatusCode, ApnsNotification notification)
27-
: base ("Apns notification error: '" + errorStatusCode + "'")
29+
: base ("Apns notification error: '" + errorStatusCode + "'", notification)
2830
{
2931
Notification = notification;
3032
ErrorStatusCode = errorStatusCode;
3133
}
3234

33-
public ApnsNotification Notification { get; set; }
35+
public ApnsNotificationException (ApnsNotificationErrorStatusCode errorStatusCode, ApnsNotification notification, Exception innerException)
36+
: base ("Apns notification error: '" + errorStatusCode + "'", notification, innerException)
37+
{
38+
Notification = notification;
39+
ErrorStatusCode = errorStatusCode;
40+
}
3441

42+
public new ApnsNotification Notification { get; set; }
3543
public ApnsNotificationErrorStatusCode ErrorStatusCode { get; private set; }
3644

3745
private static ApnsNotificationErrorStatusCode ToErrorStatusCode(byte errorStatusCode)

PushSharp.Blackberry/BlackberryConnection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public async Task Send (BlackberryNotification notification)
7272
status.NotificationStatus = notStatus;
7373

7474
if (status.NotificationStatus == BlackberryNotificationStatus.NoAppReceivePush)
75-
throw new DeviceSubscriptonExpiredException ();
75+
throw new DeviceSubscriptonExpiredException (notification);
7676

7777
if (status.HttpStatus == HttpStatusCode.OK
7878
&& status.NotificationStatus == BlackberryNotificationStatus.RequestAcceptedForProcessing)

PushSharp.Blackberry/Exceptions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ public class BlackberryNotificationException : NotificationException
99
public BlackberryNotificationException (BlackberryMessageStatus msgStatus, string desc, BlackberryNotification notification)
1010
:base (desc + " - " + msgStatus, notification)
1111
{
12+
Notification = notification;
1213
MessageStatus = msgStatus;
1314
}
1415

16+
public new BlackberryNotification Notification { get; set; }
17+
1518
public BlackberryMessageStatus MessageStatus { get; private set; }
1619
}
1720
}

PushSharp.Core/Exceptions.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
using System;
2+
using System.Collections.Generic;
23

34
namespace PushSharp.Core
45
{
5-
public class DeviceSubscriptonExpiredException : Exception
6+
public class DeviceSubscriptonExpiredException : NotificationException
67
{
7-
public DeviceSubscriptonExpiredException () : base ("Device Subscription has Expired")
8+
public DeviceSubscriptonExpiredException (INotification notification) : base ("Device Subscription has Expired", notification)
89
{
910
ExpiredAt = DateTime.UtcNow;
1011
}
@@ -30,9 +31,9 @@ public NotificationException (string message, INotification notification, Except
3031
public INotification Notification { get; set; }
3132
}
3233

33-
public class RetryAfterException : Exception
34+
public class RetryAfterException : NotificationException
3435
{
35-
public RetryAfterException (string message, DateTime retryAfterUtc) : base (message)
36+
public RetryAfterException (INotification notification, string message, DateTime retryAfterUtc) : base (message, notification)
3637
{
3738
RetryAfterUtc = retryAfterUtc;
3839
}

PushSharp.Firefox/Exceptions.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using PushSharp.Core;
3+
4+
namespace PushSharp.Firefox
5+
{
6+
public class FirefoxNotificationException : NotificationException
7+
{
8+
public FirefoxNotificationException (FirefoxNotification notification, string msg)
9+
: base (msg, notification)
10+
{
11+
Notification = notification;
12+
}
13+
14+
public new FirefoxNotification Notification { get; private set; }
15+
}
16+
}

PushSharp.Firefox/FirefoxConnection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public async Task Send (FirefoxNotification notification)
4343
var result = await http.PutAsync (notification.EndPointUrl, new StringContent (data));
4444

4545
if (result.StatusCode != HttpStatusCode.OK && result.StatusCode != HttpStatusCode.NoContent) {
46-
throw new NotificationException ("Notification Failed", notification);
46+
throw new FirefoxNotificationException (notification, "HTTP Status: " + result.StatusCode);
4747
}
4848
}
4949
}

0 commit comments

Comments
 (0)