private static async Task <NotificationResult> GetErrorResult(HttpResponseMessage response) { var content = await response.Content.ReadAsStringAsync(); FcmResponse fcmResponse = TryGetFcmResponse(content); NotificationErrorCode errorCode = GetErrorCodeFromResponse(fcmResponse); return(NotificationResult.WithError(errorCode, $"{response.StatusCode}:{fcmResponse?.Error.Message}; Details: {content}")); }
private async Task <NotificationResult> GetErrorResult(HttpResponseMessage response) { var content = await response.Content.ReadAsStringAsync(); ApnsError apnsError = TryGetApnsError(content); NotificationErrorCode errorCode = GetErrorCodeFromResponse(response, apnsError); return(NotificationResult.WithError(errorCode, $"{response.StatusCode}:{content}")); }
/// <summary> /// Occurs when a notification failed to send. /// </summary> /// <param name="notification">The notification that failed to send.</param> /// <param name="errorCode">The error code for the notification.</param> /// <param name="accountId">The id of the account the notification was intended for.</param> /// <param name="description">A description of the failure.</param> /// <param name="destination">The id of the destination for the notification.</param> /// <param name="endpointName">The endpoint the notification was intended for.</param> protected void OnFailed( Notification notification, NotificationErrorCode errorCode, string accountId, string description, string destination = null, string endpointName = null) { this.eventPublisher.Publish( new NotificationSendFailure( notification, errorCode, accountId, description, destination, endpointName)); }
/// <summary> /// Initializes a new instance of the NotificationSendFailure class. /// </summary> /// <param name="notification">The notification that failed to send.</param> /// <param name="errorCode">The error code for the notification.</param> /// <param name="accountId">The id of the account the notification was intended for.</param> /// <param name="description">A description of the failure.</param> /// <param name="destination">The id of the destination for the notification.</param> /// <param name="endpointName">The endpoint the notification was intended for.</param> internal NotificationSendFailure( Notification notification, NotificationErrorCode errorCode, string accountId, string description, string destination = null, string endpointName = null) : base(notification) { Throw.IfArgumentNullOrWhitespace(description, nameof(description)); this.AccountId = accountId; this.ErrorCode = errorCode; this.Description = description; this.Destination = destination; this.EndpointName = endpointName; }
/// <summary> /// Get response with error. /// </summary> /// <param name="errorCode"></param> /// <param name="message"></param> /// <returns></returns> public static NotificationResult WithError(NotificationErrorCode errorCode, string message) { return(new NotificationResult { Success = false, Error = new NotificationError(errorCode, message) }); }
/// <summary> /// Constructor. /// </summary> /// <param name="code">Error code.</param> /// <param name="message">Message.</param> public NotificationError(NotificationErrorCode code, string message) { Code = code; Message = message; }
public NotificationException(NotificationErrorCode errorCode, string message, Exception innerException) : base(message, innerException) { ErrorCode = errorCode; }
public NotificationException(NotificationErrorCode errorCode, string message) : base(message) { ErrorCode = errorCode; }
private void AssertSentFailed(NotificationTest test, NotificationAccount <Guid> account, PushNotification expectedNotification, NotificationErrorCode expectedErrorCode) { NotificationSendFailure notificationSendFailure = test.RaisedEvents.OfType <NotificationSendFailure>().SingleOrDefault(); notificationSendFailure.Should().NotBeNull(); notificationSendFailure.AccountId.ShouldBeEquivalentTo(account.AccountId.ToString()); notificationSendFailure.Description.Should().NotBeNull(); notificationSendFailure.ErrorCode.ShouldBeEquivalentTo(expectedErrorCode); if (expectedErrorCode == NotificationErrorCode.RouteFailure) { notificationSendFailure.EndpointName.ShouldBeEquivalentTo(Constants.PushNotificationEndPoint); } else { notificationSendFailure.EndpointName.Should().BeNull(); } if (account.MobileDevices != null && account.MobileDevices.Any()) { notificationSendFailure.Destination.ShouldBeEquivalentTo(account.MobileDevices.Single().DeviceId); } else { notificationSendFailure.Destination.Should().BeNull(); } this.AssertNotification((PushNotification)notificationSendFailure.Notification, expectedNotification); }