private static Exception CreateExceptionForNsError(NSError error) { var innerException = new NSErrorException(error); if ((error.Domain == NSError.NSUrlErrorDomain) || (error.Domain == NSError.CFNetworkErrorDomain)) { switch ((NSUrlError)(long)error.Code) { case NSUrlError.Cancelled: case NSUrlError.UserCancelledAuthentication: case (NSUrlError)NSNetServicesStatus.CancelledError: return(new OperationCanceledException(error.LocalizedDescription, innerException)); case NSUrlError.SecureConnectionFailed: case NSUrlError.ServerCertificateHasBadDate: case NSUrlError.ServerCertificateHasUnknownRoot: case NSUrlError.ServerCertificateNotYetValid: case NSUrlError.ServerCertificateUntrusted: case NSUrlError.ClientCertificateRejected: case NSUrlError.ClientCertificateRequired: return(new HttpRequestException(error.LocalizedDescription, new AuthenticationException(error.LocalizedDescription, innerException))); } } return(new HttpRequestException(error.LocalizedDescription, innerException)); }
void HandleSubscribeError(NSErrorException ex) { var error = ex.Error; Error errorResult = HandleError(error); switch (errorResult) { case Error.Success: if (error.Code == (long)CKErrorCode.UnknownItem) { Console.WriteLine("If you see this it's because you've tried to subscribe to new Post records when CloudKit hasn't seen the Post record type yet. Either manually create the record type in dashboard or upload a post"); } CheckSubscription(); break; case Error.Retry: Utils.Retry(ToggleSubscription, error); break; case Error.Ignore: Console.WriteLine("Ignored error while saving subscription: {0}", error.Description); break; default: break; } }
private void CreateLocalNotification(NotificationViewModel notificationViewModel, double timeIntervalTrigger) { InvokeOnMainThread(() => { string requestID = "newMessageNotification"; // For already delivered Notifications, the existing Notification will get updated and promoted to the top // of the list on the Home and Lock screens and in the Notification Center if it has already been read by the user. UNUserNotificationCenter.Current.GetNotificationSettings(settings => { bool alertsAllowed = (settings.AlertSetting == UNNotificationSetting.Enabled); if (alertsAllowed) { UNMutableNotificationContent content = new UNMutableNotificationContent { Title = notificationViewModel.Title, Body = notificationViewModel.Body, Badge = 1 }; UNTimeIntervalNotificationTrigger trigger = UNTimeIntervalNotificationTrigger.CreateTrigger(timeIntervalTrigger == 0 ? _notificationDelay : timeIntervalTrigger, false); UNNotificationRequest request = UNNotificationRequest.FromIdentifier(requestID, content, trigger); UNUserNotificationCenter.Current.AddNotificationRequest(request, err => { if (err != null) { NSErrorException e = new NSErrorException(err); LogUtils.LogException(LogSeverity.ERROR, e, $"{nameof(iOSLocalNotificationsManager)}.{nameof(CreateLocalNotification)} failed"); } }); } }); }); }
void HandleCheckSubscriptionError(NSErrorException ex) { NSError error = ex.Error; Error errorResult = HandleError(error); switch (errorResult) { case Error.Success: if (ex.Error.Code == (long)CKErrorCode.UnknownItem) { ResetButton("Subscribe"); } break; case Error.Retry: Utils.Retry(CheckSubscription, error); break; case Error.Ignore: Console.WriteLine("Ignored error while checking subscription: {0}", error.Description); ResetButton("?"); break; default: throw new NotImplementedException(); } }
public static ENException ToENException(this NSErrorException nsErrorException) { int code = (int)nsErrorException.Code switch { ApiMisuse => ENException.Code_iOS.ApiMisuse, BadFormat => ENException.Code_iOS.BadFormat, BadParameter => ENException.Code_iOS.BadParameter, BluetoothOff => ENException.Code_iOS.BluetoothOff, DataInaccessible => ENException.Code_iOS.DataInaccessible, InsufficientMemory => ENException.Code_iOS.InsufficientMemory, InsufficientStorage => ENException.Code_iOS.InsufficientStorage, Internal => ENException.Code_iOS.Internal, Invalidated => ENException.Code_iOS.Invalidated, NotAuthorized => ENException.Code_iOS.NotAuthorized, NotEnabled => ENException.Code_iOS.NotEnabled, NotEntitled => ENException.Code_iOS.NotEntitled, RateLimited => ENException.Code_iOS.RateLimited, Restricted => ENException.Code_iOS.Restricted, TravelStatusNotAvailable => ENException.Code_iOS.TravelStatusNotAvailable, Unknown => ENException.Code_iOS.Unknown, Unsupported => ENException.Code_iOS.Unsupported, _ => ENException.Code_iOS.Unknown, }; return(new ENException(code, nsErrorException.Message)); }
public static DataException ToDataException(this MSDataError error, MSDocumentWrapper msDocumentWrapper = null) { var exception = new NSErrorException(error); return(new DataException(error.LocalizedDescription, exception) { DocumentMetadata = msDocumentWrapper?.ToDocumentMetadata() }); }
public static Exception Map(NSErrorException exception) { var errorType = ErrorType.Unkown; var errorCode = (StorageErrorCode)(long)exception.Error.Code; switch (errorCode) { case StorageErrorCode.BucketNotFound: errorType = ErrorType.BucketNotFound; break; case StorageErrorCode.Cancelled: errorType = ErrorType.Canceled; break; case StorageErrorCode.NonMatchingChecksum: errorType = ErrorType.InvalidChecksum; break; case StorageErrorCode.Unauthenticated: errorType = ErrorType.NotAuthenticated; break; case StorageErrorCode.Unauthorized: errorType = ErrorType.NotAuthorized; break; case StorageErrorCode.ObjectNotFound: errorType = ErrorType.ObjectNotFound; break; case StorageErrorCode.ProjectNotFound: errorType = ErrorType.ProjectNotFound; break; case StorageErrorCode.QuotaExceeded: errorType = ErrorType.QuotaExceeded; break; case StorageErrorCode.RetryLimitExceeded: errorType = ErrorType.RetryLimitExceeded; break; case StorageErrorCode.DownloadSizeExceeded: errorType = ErrorType.DownloadSizeExceeded; break; } return(new FirebaseStorageException(exception.Message, exception, errorType)); }
private FirebaseAuthException GetFirebaseAuthException(NSErrorException ex) { AuthErrorCode errorCode; if (IntPtr.Size == 8) // 64 bits devices { errorCode = (AuthErrorCode)((long)ex.Error.Code); } else // 32 bits devices { errorCode = (AuthErrorCode)((int)ex.Error.Code); } FirebaseAuthService.FirebaseExceptionTypeToEnumDict.TryGetValue(errorCode, out FirebaseAuthExceptionType exceptionType); return(new FirebaseAuthException(ex.Message, ex, exceptionType)); }
public Task <BTPaymentMethodNonce> TokenizeCardAsync(BTCard card) { var tcs = new TaskCompletionSource <BTPaymentMethodNonce>(); TokenizeCard(card, (nonce, error) => { if (error != null) { var exception = new NSErrorException(error); tcs.TrySetException(exception); } tcs.TrySetResult((BTPaymentMethodNonce)nonce); }); return(tcs.Task); }
public Task<BTPaymentMethodNonce> TokenizeCardAsync(BTCard card) { var tcs = new TaskCompletionSource<BTPaymentMethodNonce>(); TokenizeCard(card, (nonce, error) => { if(error != null) { var exception = new NSErrorException(error); tcs.TrySetException(exception); } tcs.TrySetResult((BTPaymentMethodNonce)nonce); }); return tcs.Task; }
void HandleUnsubscribeError(NSErrorException ex) { var error = ex.Error; var errorResult = HandleError(error); switch (errorResult) { case Error.Retry: Utils.Retry(ToggleSubscription, error); break; case Error.Ignore: Console.WriteLine("Ignored error while deleting subscription: {0}", error.Description); break; default: throw new NotImplementedException(); } }
public Task<BTPaymentMethodNonce> AuthorizeAccountWithCompletion() { var tcs = new TaskCompletionSource<BTPaymentMethodNonce>(); AuthorizeAccountWithCompletion((paypalNonce, error) => { if(error != null) { var exception = new NSErrorException(error); tcs.TrySetException(exception); return; } tcs.TrySetResult((BTPaymentMethodNonce)paypalNonce); }); return tcs.Task; }
public Task <BTPaymentMethodNonce> AuthorizeAccountWithCompletion() { var tcs = new TaskCompletionSource <BTPaymentMethodNonce>(); AuthorizeAccountWithCompletion((paypalNonce, error) => { if (error != null) { var exception = new NSErrorException(error); tcs.TrySetException(exception); return; } tcs.TrySetResult((BTPaymentMethodNonce)paypalNonce); }); return(tcs.Task); }
private void ScheduleSendEventLog() { _loggerService.StartMethod(); var bgTaskRequest = new BGProcessingTaskRequest(IDENTIFIER) { EarliestBeginDate = NSDate.FromTimeIntervalSinceNow(ONE_DAY_IN_SECONDS), RequiresNetworkConnectivity = true }; _loggerService.Info($"request.EarliestBeginDate: {bgTaskRequest.EarliestBeginDate}"); _ = BGTaskScheduler.Shared.Submit(bgTaskRequest, out var error); if (error != null) { NSErrorException exception = new NSErrorException(error); _loggerService.Exception("BGTaskScheduler submit failed.", exception); throw exception; } _loggerService.EndMethod(); }
public Task <BTPaymentMethodNonce> AuthorizeAccountWithAdditionalScopesAsync(string[] payload) { var tcs = new TaskCompletionSource <BTPaymentMethodNonce>(); var paypalScope = new NSSet <NSString>(payload.Select(p => new NSString(p)).ToArray()); AuthorizeAccountWithAdditionalScopes(paypalScope, (paypalNonce, error) => { if (error != null) { var exception = new NSErrorException(error); tcs.TrySetException(exception); return; } tcs.TrySetResult((BTPaymentMethodNonce)paypalNonce); }); return(tcs.Task); }
public Task<BTPaymentMethodNonce> AuthorizeAccountWithAdditionalScopesAsync(string[] payload) { var tcs = new TaskCompletionSource<BTPaymentMethodNonce>(); var paypalScope = new NSSet<NSString>(payload.Select(p => new NSString(p)).ToArray()); AuthorizeAccountWithAdditionalScopes(paypalScope, (paypalNonce, error) => { if(error != null) { var exception = new NSErrorException(error); tcs.TrySetException(exception); return; } tcs.TrySetResult((BTPaymentMethodNonce)paypalNonce); }); return tcs.Task; }
void HandleSubscribeError (NSErrorException ex) { var error = ex.Error; Error errorResult = HandleError (error); switch (errorResult) { case Error.Success: if (error.Code == (long)CKErrorCode.UnknownItem) Console.WriteLine ("If you see this it's because you've tried to subscribe to new Post records when CloudKit hasn't seen the Post record type yet. Either manually create the record type in dashboard or upload a post"); CheckSubscription (); break; case Error.Retry: Utils.Retry (ToggleSubscription, error); break; case Error.Ignore: Console.WriteLine ("Ignored error while saving subscription: {0}", error.Description); break; default: break; } }
private void ScheduleBgTask(DateTime nextDateTime) { LoggerService.StartMethod(); try { BGProcessingTaskRequest bgTaskRequest = new BGProcessingTaskRequest(BGTASK_IDENTIFIER) { EarliestBeginDate = NSDate.FromTimeIntervalSince1970(nextDateTime.ToUnixEpoch()) }; BGTaskScheduler.Shared.Submit(bgTaskRequest, out var error); if (error != null) { NSErrorException exception = new NSErrorException(error); LoggerService.Exception("BGTaskScheduler submit failed.", exception); throw exception; } } finally { LoggerService.EndMethod(); } }
private void ScheduleBgTask() { _loggerService.StartMethod(); try { BGProcessingTaskRequest bgTaskRequest = new BGProcessingTaskRequest(BGTASK_IDENTIFIER) { RequiresNetworkConnectivity = true }; BGTaskScheduler.Shared.Submit(bgTaskRequest, out var error); if (error != null) { NSErrorException exception = new NSErrorException(error); _loggerService.Exception("BGTaskScheduler submit failed.", exception); throw exception; } } finally { _loggerService.EndMethod(); } }
public static Exception Map(NSErrorException exception) { var errorType = ErrorType.Other; string reason = null; var errorCode = (AuthErrorCode)(long)exception.Error.Code; switch (errorCode) { case AuthErrorCode.NetworkError: errorType = ErrorType.NetWork; break; case AuthErrorCode.TooManyRequests: errorType = ErrorType.TooManyRequests; break; case AuthErrorCode.InvalidRecipientEmail: case AuthErrorCode.InvalidSender: case AuthErrorCode.InvalidMessagePayload: errorType = ErrorType.Email; break; case AuthErrorCode.InvalidActionCode: case AuthErrorCode.ExpiredActionCode: errorType = ErrorType.ActionCode; break; case AuthErrorCode.UserDisabled: case AuthErrorCode.UserNotFound: case AuthErrorCode.UserTokenExpired: case AuthErrorCode.InvalidUserToken: errorType = ErrorType.InvalidUser; break; case AuthErrorCode.WeakPassword: errorType = ErrorType.WeakPassword; reason = exception.Error.UserInfo[NSError.LocalizedFailureReasonErrorKey] as NSString; break; case AuthErrorCode.EmailAlreadyInUse: case AuthErrorCode.AccountExistsWithDifferentCredential: case AuthErrorCode.CredentialAlreadyInUse: errorType = ErrorType.UserCollision; break; case AuthErrorCode.RequiresRecentLogin: errorType = ErrorType.RecentLoginRequired; break; case AuthErrorCode.InvalidCredential: case AuthErrorCode.InvalidEmail: case AuthErrorCode.WrongPassword: case AuthErrorCode.InvalidCustomToken: case AuthErrorCode.CustomTokenMismatch: case AuthErrorCode.InvalidPhoneNumber: case AuthErrorCode.MissingPhoneNumber: case AuthErrorCode.InvalidVerificationID: case AuthErrorCode.MissingVerificationID: case AuthErrorCode.InvalidVerificationCode: case AuthErrorCode.MissingVerificationCode: errorType = ErrorType.InvalidCredentials; break; } return(new FirebaseAuthException(exception.Error.LocalizedDescription, exception, errorType, reason)); }
public static Exception Map(NSErrorException exception) { var errorType = ErrorType.Unknown; var errorCode = (FirestoreErrorCode)(long)exception.Error.Code; switch (errorCode) { case FirestoreErrorCode.Ok: errorType = ErrorType.OK; break; case FirestoreErrorCode.Cancelled: errorType = ErrorType.Cancelled; break; case FirestoreErrorCode.Unknown: errorType = ErrorType.Unknown; break; case FirestoreErrorCode.InvalidArgument: errorType = ErrorType.InvalidArgument; break; case FirestoreErrorCode.DeadlineExceeded: errorType = ErrorType.DeadlineExceeded; break; case FirestoreErrorCode.NotFound: errorType = ErrorType.NotFound; break; case FirestoreErrorCode.AlreadyExists: errorType = ErrorType.AlreadyExists; break; case FirestoreErrorCode.PermissionDenied: errorType = ErrorType.PermissionDenied; break; case FirestoreErrorCode.ResourceExhausted: errorType = ErrorType.ResourceExhausted; break; case FirestoreErrorCode.FailedPrecondition: errorType = ErrorType.FailedPrecondition; break; case FirestoreErrorCode.Aborted: errorType = ErrorType.Aborted; break; case FirestoreErrorCode.OutOfRange: errorType = ErrorType.OutOfRange; break; case FirestoreErrorCode.Unimplemented: errorType = ErrorType.Unimplemented; break; case FirestoreErrorCode.Internal: errorType = ErrorType.Internal; break; case FirestoreErrorCode.Unavailable: errorType = ErrorType.Unavailable; break; case FirestoreErrorCode.DataLoss: errorType = ErrorType.DataLoss; break; case FirestoreErrorCode.Unauthenticated: errorType = ErrorType.Unauthenticated; break; } return(new CloudFirestoreException(exception.Error.LocalizedDescription, errorType, exception)); }
// almost identical to ModernHttpClient version but it uses the constants from monotouch.dll | Xamarin.[iOS|WatchOS|TVOS].dll static Exception createExceptionForNSError(NSError error) { // var webExceptionStatus = WebExceptionStatus.UnknownError; var innerException = new NSErrorException(error); // errors that exists in both share the same error code, so we can use a single switch/case // this also ease watchOS integration as if does not expose CFNetwork but (I would not be // surprised if it)could return some of it's error codes #if __WATCHOS__ if (error.Domain == NSError.NSUrlErrorDomain) { #else if ((error.Domain == NSError.NSUrlErrorDomain) || (error.Domain == NSError.CFNetworkErrorDomain)) { #endif // Parse the enum into a web exception status or exception. Some // of these values don't necessarily translate completely to // what WebExceptionStatus supports, so made some best guesses // here. For your reading pleasure, compare these: // // Apple docs: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/index.html#//apple_ref/doc/constant_group/URL_Loading_System_Error_Codes // .NET docs: http://msdn.microsoft.com/en-us/library/system.net.webexceptionstatus(v=vs.110).aspx switch ((NSUrlError)(long)error.Code) { case NSUrlError.Cancelled: case NSUrlError.UserCancelledAuthentication: #if !__WATCHOS__ case (NSUrlError)NSNetServicesStatus.CancelledError: #endif // No more processing is required so just return. return(new OperationCanceledException(error.LocalizedDescription, innerException)); // case NSUrlError.BadURL: // case NSUrlError.UnsupportedURL: // case NSUrlError.CannotConnectToHost: // case NSUrlError.ResourceUnavailable: // case NSUrlError.NotConnectedToInternet: // case NSUrlError.UserAuthenticationRequired: // case NSUrlError.InternationalRoamingOff: // case NSUrlError.CallIsActive: // case NSUrlError.DataNotAllowed: // #if !__WATCHOS__ // case (NSUrlError) CFNetworkErrors.Socks5BadCredentials: // case (NSUrlError) CFNetworkErrors.Socks5UnsupportedNegotiationMethod: // case (NSUrlError) CFNetworkErrors.Socks5NoAcceptableMethod: // case (NSUrlError) CFNetworkErrors.HttpAuthenticationTypeUnsupported: // case (NSUrlError) CFNetworkErrors.HttpBadCredentials: // case (NSUrlError) CFNetworkErrors.HttpBadURL: // #endif // webExceptionStatus = WebExceptionStatus.ConnectFailure; // break; // case NSUrlError.TimedOut: // #if !__WATCHOS__ // case (NSUrlError) CFNetworkErrors.NetServiceTimeout: // #endif // webExceptionStatus = WebExceptionStatus.Timeout; // break; // case NSUrlError.CannotFindHost: // case NSUrlError.DNSLookupFailed: // #if !__WATCHOS__ // case (NSUrlError) CFNetworkErrors.HostNotFound: // case (NSUrlError) CFNetworkErrors.NetServiceDnsServiceFailure: // #endif // webExceptionStatus = WebExceptionStatus.NameResolutionFailure; // break; // case NSUrlError.DataLengthExceedsMaximum: // webExceptionStatus = WebExceptionStatus.MessageLengthLimitExceeded; // break; // case NSUrlError.NetworkConnectionLost: // #if !__WATCHOS__ // case (NSUrlError) CFNetworkErrors.HttpConnectionLost: // #endif // webExceptionStatus = WebExceptionStatus.ConnectionClosed; // break; // case NSUrlError.HTTPTooManyRedirects: // case NSUrlError.RedirectToNonExistentLocation: // #if !__WATCHOS__ // case (NSUrlError) CFNetworkErrors.HttpRedirectionLoopDetected: // #endif // webExceptionStatus = WebExceptionStatus.ProtocolError; // break; // case NSUrlError.RequestBodyStreamExhausted: // #if !__WATCHOS__ // case (NSUrlError) CFNetworkErrors.SocksUnknownClientVersion: // case (NSUrlError) CFNetworkErrors.SocksUnsupportedServerVersion: // case (NSUrlError) CFNetworkErrors.HttpParseFailure: // #endif // webExceptionStatus = WebExceptionStatus.SendFailure; // break; // case NSUrlError.BadServerResponse: // case NSUrlError.ZeroByteResource: // case NSUrlError.CannotDecodeRawData: // case NSUrlError.CannotDecodeContentData: // case NSUrlError.CannotParseResponse: // case NSUrlError.FileDoesNotExist: // case NSUrlError.FileIsDirectory: // case NSUrlError.NoPermissionsToReadFile: // case NSUrlError.CannotLoadFromNetwork: // case NSUrlError.CannotCreateFile: // case NSUrlError.CannotOpenFile: // case NSUrlError.CannotCloseFile: // case NSUrlError.CannotWriteToFile: // case NSUrlError.CannotRemoveFile: // case NSUrlError.CannotMoveFile: // case NSUrlError.DownloadDecodingFailedMidStream: // case NSUrlError.DownloadDecodingFailedToComplete: // #if !__WATCHOS__ // case (NSUrlError) CFNetworkErrors.Socks4RequestFailed: // case (NSUrlError) CFNetworkErrors.Socks4IdentdFailed: // case (NSUrlError) CFNetworkErrors.Socks4IdConflict: // case (NSUrlError) CFNetworkErrors.Socks4UnknownStatusCode: // case (NSUrlError) CFNetworkErrors.Socks5BadState: // case (NSUrlError) CFNetworkErrors.Socks5BadResponseAddr: // case (NSUrlError) CFNetworkErrors.CannotParseCookieFile: // case (NSUrlError) CFNetworkErrors.NetServiceUnknown: // case (NSUrlError) CFNetworkErrors.NetServiceCollision: // case (NSUrlError) CFNetworkErrors.NetServiceNotFound: // case (NSUrlError) CFNetworkErrors.NetServiceInProgress: // case (NSUrlError) CFNetworkErrors.NetServiceBadArgument: // case (NSUrlError) CFNetworkErrors.NetServiceInvalid: // #endif // webExceptionStatus = WebExceptionStatus.ReceiveFailure; // break; // case NSUrlError.SecureConnectionFailed: // webExceptionStatus = WebExceptionStatus.SecureChannelFailure; // break; // case NSUrlError.ServerCertificateHasBadDate: // case NSUrlError.ServerCertificateHasUnknownRoot: // case NSUrlError.ServerCertificateNotYetValid: // case NSUrlError.ServerCertificateUntrusted: // case NSUrlError.ClientCertificateRejected: // case NSUrlError.ClientCertificateRequired: // webExceptionStatus = WebExceptionStatus.TrustFailure; // break; // #if !__WATCHOS__ // case (NSUrlError) CFNetworkErrors.HttpProxyConnectionFailure: // case (NSUrlError) CFNetworkErrors.HttpBadProxyCredentials: // case (NSUrlError) CFNetworkErrors.PacFileError: // case (NSUrlError) CFNetworkErrors.PacFileAuth: // case (NSUrlError) CFNetworkErrors.HttpsProxyConnectionFailure: // case (NSUrlError) CFNetworkErrors.HttpsProxyFailureUnexpectedResponseToConnectMethod: // webExceptionStatus = WebExceptionStatus.RequestProhibitedByProxy; // break; // #endif } } // Always create a WebException so that it can be handled by the client. return(new WebException(error.LocalizedDescription, innerException)); //, webExceptionStatus, response: null); } string GetHeaderSeparator(string name) { string value; if (!headerSeparators.TryGetValue(name, out value)) { value = ","; } return(value); } async Task <NSUrlRequest> CreateRequest(HttpRequestMessage request) { var stream = Stream.Null; var headers = request.Headers as IEnumerable <KeyValuePair <string, IEnumerable <string> > >; if (request.Content != null) { stream = await request.Content.ReadAsStreamAsync().ConfigureAwait(false); headers = System.Linq.Enumerable.ToArray(headers.Union(request.Content.Headers)); } var nsrequest = new NSMutableUrlRequest { AllowsCellularAccess = true, CachePolicy = DisableCaching ? NSUrlRequestCachePolicy.ReloadIgnoringCacheData : NSUrlRequestCachePolicy.UseProtocolCachePolicy, HttpMethod = request.Method.ToString().ToUpperInvariant(), Url = NSUrl.FromString(request.RequestUri.AbsoluteUri), Headers = headers.Aggregate(new NSMutableDictionary(), (acc, x) => { acc.Add(new NSString(x.Key), new NSString(string.Join(GetHeaderSeparator(x.Key), x.Value))); return(acc); }) }; if (stream != Stream.Null) { // HttpContent.TryComputeLength is `protected internal` :-( but it's indirectly called by headers var length = request.Content.Headers.ContentLength; if (length.HasValue && (length <= MaxInputInMemory)) { nsrequest.Body = NSData.FromStream(stream); } else { nsrequest.BodyStream = new WrappedNSInputStream(stream); } } return(nsrequest); }
private static Exception CreateExceptionForNsError(NSError error) { var webExceptionStatus = WebExceptionStatus.UnknownError; var innerException = new NSErrorException(error); // errors that exists in both share the same error code, so we can use a single switch/case // this also ease watchOS integration as if does not expose CFNetwork but (I would not be // surprised if it)could return some of it's error codes if ((error.Domain == NSError.NSUrlErrorDomain) || (error.Domain == NSError.CFNetworkErrorDomain)) { // Parse the enum into a web exception status or exception. Some // of these values don't necessarily translate completely to // what WebExceptionStatus supports, so made some best guesses // here. For your reading pleasure, compare these: // // Apple docs: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/index.html#//apple_ref/doc/constant_group/URL_Loading_System_Error_Codes // .NET docs: http://msdn.microsoft.com/en-us/library/system.net.webexceptionstatus(v=vs.110).aspx switch ((NSUrlError)(long)error.Code) { case NSUrlError.Cancelled: case NSUrlError.UserCancelledAuthentication: case (NSUrlError)NSNetServicesStatus.CancelledError: // No more processing is required so just return. return(new OperationCanceledException(error.LocalizedDescription, innerException)); case NSUrlError.BadURL: case NSUrlError.UnsupportedURL: case NSUrlError.CannotConnectToHost: case NSUrlError.ResourceUnavailable: case NSUrlError.NotConnectedToInternet: case NSUrlError.UserAuthenticationRequired: case NSUrlError.InternationalRoamingOff: case NSUrlError.CallIsActive: case NSUrlError.DataNotAllowed: case (NSUrlError)CFNetworkErrors.Socks5BadCredentials: case (NSUrlError)CFNetworkErrors.Socks5UnsupportedNegotiationMethod: case (NSUrlError)CFNetworkErrors.Socks5NoAcceptableMethod: case (NSUrlError)CFNetworkErrors.HttpAuthenticationTypeUnsupported: case (NSUrlError)CFNetworkErrors.HttpBadCredentials: case (NSUrlError)CFNetworkErrors.HttpBadURL: webExceptionStatus = WebExceptionStatus.ConnectFailure; break; case NSUrlError.TimedOut: case (NSUrlError)CFNetworkErrors.NetServiceTimeout: webExceptionStatus = WebExceptionStatus.Timeout; break; case NSUrlError.CannotFindHost: case NSUrlError.DNSLookupFailed: case (NSUrlError)CFNetworkErrors.HostNotFound: case (NSUrlError)CFNetworkErrors.NetServiceDnsServiceFailure: webExceptionStatus = WebExceptionStatus.NameResolutionFailure; break; case NSUrlError.DataLengthExceedsMaximum: webExceptionStatus = WebExceptionStatus.MessageLengthLimitExceeded; break; case NSUrlError.NetworkConnectionLost: case (NSUrlError)CFNetworkErrors.HttpConnectionLost: webExceptionStatus = WebExceptionStatus.ConnectionClosed; break; case NSUrlError.HTTPTooManyRedirects: case NSUrlError.RedirectToNonExistentLocation: case (NSUrlError)CFNetworkErrors.HttpRedirectionLoopDetected: webExceptionStatus = WebExceptionStatus.ProtocolError; break; case NSUrlError.RequestBodyStreamExhausted: case (NSUrlError)CFNetworkErrors.SocksUnknownClientVersion: case (NSUrlError)CFNetworkErrors.SocksUnsupportedServerVersion: case (NSUrlError)CFNetworkErrors.HttpParseFailure: webExceptionStatus = WebExceptionStatus.SendFailure; break; case NSUrlError.BadServerResponse: case NSUrlError.ZeroByteResource: case NSUrlError.CannotDecodeRawData: case NSUrlError.CannotDecodeContentData: case NSUrlError.CannotParseResponse: case NSUrlError.FileDoesNotExist: case NSUrlError.FileIsDirectory: case NSUrlError.NoPermissionsToReadFile: case NSUrlError.CannotLoadFromNetwork: case NSUrlError.CannotCreateFile: case NSUrlError.CannotOpenFile: case NSUrlError.CannotCloseFile: case NSUrlError.CannotWriteToFile: case NSUrlError.CannotRemoveFile: case NSUrlError.CannotMoveFile: case NSUrlError.DownloadDecodingFailedMidStream: case NSUrlError.DownloadDecodingFailedToComplete: case (NSUrlError)CFNetworkErrors.Socks4RequestFailed: case (NSUrlError)CFNetworkErrors.Socks4IdentdFailed: case (NSUrlError)CFNetworkErrors.Socks4IdConflict: case (NSUrlError)CFNetworkErrors.Socks4UnknownStatusCode: case (NSUrlError)CFNetworkErrors.Socks5BadState: case (NSUrlError)CFNetworkErrors.Socks5BadResponseAddr: case (NSUrlError)CFNetworkErrors.CannotParseCookieFile: case (NSUrlError)CFNetworkErrors.NetServiceUnknown: case (NSUrlError)CFNetworkErrors.NetServiceCollision: case (NSUrlError)CFNetworkErrors.NetServiceNotFound: case (NSUrlError)CFNetworkErrors.NetServiceInProgress: case (NSUrlError)CFNetworkErrors.NetServiceBadArgument: case (NSUrlError)CFNetworkErrors.NetServiceInvalid: webExceptionStatus = WebExceptionStatus.ReceiveFailure; break; case NSUrlError.SecureConnectionFailed: webExceptionStatus = WebExceptionStatus.SecureChannelFailure; break; case NSUrlError.ServerCertificateHasBadDate: case NSUrlError.ServerCertificateHasUnknownRoot: case NSUrlError.ServerCertificateNotYetValid: case NSUrlError.ServerCertificateUntrusted: case NSUrlError.ClientCertificateRejected: case NSUrlError.ClientCertificateRequired: webExceptionStatus = WebExceptionStatus.TrustFailure; break; case (NSUrlError)CFNetworkErrors.HttpProxyConnectionFailure: case (NSUrlError)CFNetworkErrors.HttpBadProxyCredentials: case (NSUrlError)CFNetworkErrors.PacFileError: case (NSUrlError)CFNetworkErrors.PacFileAuth: case (NSUrlError)CFNetworkErrors.HttpsProxyConnectionFailure: case (NSUrlError)CFNetworkErrors.HttpsProxyFailureUnexpectedResponseToConnectMethod: webExceptionStatus = WebExceptionStatus.RequestProhibitedByProxy; break; } } // Always create a WebException so that it can be handled by the client. return(new WebException(error.LocalizedDescription, innerException, webExceptionStatus, response: null)); }
static Exception createExceptionForNSError(NSError error) { var innerException = new NSErrorException(error); // errors that exists in both share the same error code, so we can use a single switch/case // this also ease watchOS integration as if does not expose CFNetwork but (I would not be // surprised if it)could return some of it's error codes #if __WATCHOS__ if (error.Domain == NSError.NSUrlErrorDomain) { #else if ((error.Domain == NSError.NSUrlErrorDomain) || (error.Domain == NSError.CFNetworkErrorDomain)) { #endif // Apple docs: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/index.html#//apple_ref/doc/constant_group/URL_Loading_System_Error_Codes // .NET docs: http://msdn.microsoft.com/en-us/library/system.net.webexceptionstatus(v=vs.110).aspx switch ((NSUrlError)(long)error.Code) { case NSUrlError.Cancelled: case NSUrlError.UserCancelledAuthentication: #if !__WATCHOS__ case (NSUrlError)NSNetServicesStatus.CancelledError: #endif // No more processing is required so just return. return(new OperationCanceledException(error.LocalizedDescription, innerException)); } } return(new HttpRequestException(error.LocalizedDescription, innerException)); } string GetHeaderSeparator(string name) { string value; if (!headerSeparators.TryGetValue(name, out value)) { value = ","; } return(value); } async Task <NSUrlRequest> CreateRequest(HttpRequestMessage request) { var stream = Stream.Null; var headers = request.Headers as IEnumerable <KeyValuePair <string, IEnumerable <string> > >; if (request.Content != null) { stream = await request.Content.ReadAsStreamAsync().ConfigureAwait(false); headers = System.Linq.Enumerable.ToArray(headers.Union(request.Content.Headers)); } var nsrequest = new NSMutableUrlRequest { AllowsCellularAccess = allowsCellularAccess, CachePolicy = DisableCaching ? NSUrlRequestCachePolicy.ReloadIgnoringCacheData : NSUrlRequestCachePolicy.UseProtocolCachePolicy, HttpMethod = request.Method.ToString().ToUpperInvariant(), Url = NSUrl.FromString(request.RequestUri.AbsoluteUri), Headers = headers.Aggregate(new NSMutableDictionary(), (acc, x) => { acc.Add(new NSString(x.Key), new NSString(string.Join(GetHeaderSeparator(x.Key), x.Value))); return(acc); }) }; if (stream != Stream.Null) { // HttpContent.TryComputeLength is `protected internal` :-( but it's indirectly called by headers var length = request.Content.Headers.ContentLength; if (length.HasValue && (length <= MaxInputInMemory)) { nsrequest.Body = NSData.FromStream(stream); } else { nsrequest.BodyStream = new WrappedNSInputStream(stream); } } return(nsrequest); }
void HandleCheckSubscriptionError(NSErrorException ex) { NSError error = ex.Error; Error errorResult = HandleError (error); switch (errorResult) { case Error.Success: if (ex.Error.Code == (long)CKErrorCode.UnknownItem) ResetButton ("Subscribe"); break; case Error.Retry: Utils.Retry (CheckSubscription, error); break; case Error.Ignore: Console.WriteLine ("Ignored error while checking subscription: {0}", error.Description); ResetButton ("?"); break; default: throw new NotImplementedException (); } }
public static Exception Map(NSErrorException exception) { var authErrorCode = (AuthErrorCode)(long)exception.Error.Code; var userInfo = exception.Error.UserInfo; var errorCode = userInfo[Auth.ErrorUserInfoNameKey] as NSString; var message = userInfo[NSError.LocalizedDescriptionKey] as NSString; switch (authErrorCode) { case AuthErrorCode.NetworkError: case AuthErrorCode.WebNetworkRequestFailed: return(new FirebaseAuthException(message, exception, ErrorType.NetWork, errorCode)); case AuthErrorCode.InvalidMessagePayload: case AuthErrorCode.InvalidSender: case AuthErrorCode.InvalidRecipientEmail: return(new FirebaseAuthException(message, exception, ErrorType.Email, errorCode)); case AuthErrorCode.ExpiredActionCode: case AuthErrorCode.InvalidActionCode: return(new FirebaseAuthException(message, exception, ErrorType.ActionCode, errorCode)); case AuthErrorCode.UserDisabled: case AuthErrorCode.UserNotFound: case AuthErrorCode.InvalidUserToken: case AuthErrorCode.UserTokenExpired: return(new FirebaseAuthException(message, exception, ErrorType.InvalidUser, errorCode)); case AuthErrorCode.TooManyRequests: case AuthErrorCode.QuotaExceeded: return(new FirebaseAuthException(message, exception, ErrorType.TooManyRequests, errorCode)); case AuthErrorCode.WeakPassword: var reason = userInfo[NSError.LocalizedFailureReasonErrorKey] as NSString; return(new FirebaseAuthException(message, exception, ErrorType.WeakPassword, errorCode, reason)); case AuthErrorCode.EmailAlreadyInUse: case AuthErrorCode.AccountExistsWithDifferentCredential: case AuthErrorCode.CredentialAlreadyInUse: var email = userInfo[Auth.ErrorUserInfoEmailKey] as NSString; var updateCredential = userInfo[Auth.ErrorUserInfoUpdatedCredentialKey] is AuthCredential credential ? AuthCredentialWrapperFactory.Create(credential) : null; return(new FirebaseAuthException(message, exception, ErrorType.UserCollision, errorCode, email, updateCredential)); case AuthErrorCode.InvalidCustomToken: case AuthErrorCode.CustomTokenMismatch: case AuthErrorCode.InvalidCredential: case AuthErrorCode.InvalidEmail: case AuthErrorCode.WrongPassword: case AuthErrorCode.UserMismatch: case AuthErrorCode.MissingEmail: case (AuthErrorCode)17035: case AuthErrorCode.MissingPhoneNumber: case AuthErrorCode.InvalidPhoneNumber: case AuthErrorCode.MissingVerificationCode: case AuthErrorCode.InvalidVerificationCode: case AuthErrorCode.MissingVerificationID: case AuthErrorCode.InvalidVerificationID: case (AuthErrorCode)17049: case AuthErrorCode.SessionExpired: case AuthErrorCode.RejectedCredential: case (AuthErrorCode)17077: case AuthErrorCode.MissingMultiFactorSession: case AuthErrorCode.MissingMultiFactorInfo: case AuthErrorCode.InvalidMultiFactorSession: case AuthErrorCode.MultiFactorInfoNotFound: case AuthErrorCode.MissingOrInvalidNonce: return(new FirebaseAuthException(message, exception, ErrorType.InvalidCredentials, errorCode)); case AuthErrorCode.RequiresRecentLogin: return(new FirebaseAuthException(message, exception, ErrorType.RecentLoginRequired, errorCode)); case AuthErrorCode.SecondFactorRequired: var resolver = userInfo[Auth.ErrorUserInfoMultiFactorResolverKey] is MultiFactorResolver multiFactorResolver ? new MultiFactorResolverWrapper(multiFactorResolver) : null; return(new FirebaseAuthException(message, exception, ErrorType.MultiFactor, errorCode, resolver)); case AuthErrorCode.WebContextAlreadyPresented: case AuthErrorCode.WebContextCancelled: case AuthErrorCode.WebInternalError: case (AuthErrorCode)17065: return(new FirebaseAuthException(message, exception, ErrorType.Web, errorCode)); case AuthErrorCode.WebSignInUserInteractionFailure: case (AuthErrorCode)17080: return(new FirebaseAuthException(message, exception, ErrorType.ApiNotAvailable, errorCode)); default: return(new FirebaseAuthException(message, exception, ErrorType.Other, errorCode)); } }
public static void LogD(this NSErrorException nsErrorException) { Logger.D($"Error occurred {nsErrorException.Code} - {nsErrorException.Domain} - {nsErrorException.Message}"); }
static Exception createExceptionForNSError(NSError error) { var ret = default(Exception); var webExceptionStatus = WebExceptionStatus.UnknownError; var innerException = new NSErrorException(error); if (error.Domain == NSError.NSUrlErrorDomain) { // Convert the error code into an enumeration (this is future // proof, rather than just casting integer) NSUrlErrorExtended urlError; if (!Enum.TryParse<NSUrlErrorExtended>(error.Code.ToString(), out urlError)) urlError = NSUrlErrorExtended.Unknown; // Parse the enum into a web exception status or exception. Some // of these values don't necessarily translate completely to // what WebExceptionStatus supports, so made some best guesses // here. For your reading pleasure, compare these: // // Apple docs: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/index.html#//apple_ref/doc/constant_group/URL_Loading_System_Error_Codes // .NET docs: http://msdn.microsoft.com/en-us/library/system.net.webexceptionstatus(v=vs.110).aspx switch (urlError) { case NSUrlErrorExtended.Cancelled: case NSUrlErrorExtended.UserCancelledAuthentication: // No more processing is required so just return. return new OperationCanceledException(error.LocalizedDescription, innerException); case NSUrlErrorExtended.BadURL: case NSUrlErrorExtended.UnsupportedURL: case NSUrlErrorExtended.CannotConnectToHost: case NSUrlErrorExtended.ResourceUnavailable: case NSUrlErrorExtended.NotConnectedToInternet: case NSUrlErrorExtended.UserAuthenticationRequired: case NSUrlErrorExtended.InternationalRoamingOff: case NSUrlErrorExtended.CallIsActive: case NSUrlErrorExtended.DataNotAllowed: webExceptionStatus = WebExceptionStatus.ConnectFailure; break; case NSUrlErrorExtended.TimedOut: webExceptionStatus = WebExceptionStatus.Timeout; break; case NSUrlErrorExtended.CannotFindHost: case NSUrlErrorExtended.DNSLookupFailed: webExceptionStatus = WebExceptionStatus.NameResolutionFailure; break; case NSUrlErrorExtended.DataLengthExceedsMaximum: webExceptionStatus = WebExceptionStatus.MessageLengthLimitExceeded; break; case NSUrlErrorExtended.NetworkConnectionLost: webExceptionStatus = WebExceptionStatus.ConnectionClosed; break; case NSUrlErrorExtended.HTTPTooManyRedirects: case NSUrlErrorExtended.RedirectToNonExistentLocation: webExceptionStatus = WebExceptionStatus.ProtocolError; break; case NSUrlErrorExtended.RequestBodyStreamExhausted: webExceptionStatus = WebExceptionStatus.SendFailure; break; case NSUrlErrorExtended.BadServerResponse: case NSUrlErrorExtended.ZeroByteResource: case NSUrlErrorExtended.CannotDecodeRawData: case NSUrlErrorExtended.CannotDecodeContentData: case NSUrlErrorExtended.CannotParseResponse: case NSUrlErrorExtended.FileDoesNotExist: case NSUrlErrorExtended.FileIsDirectory: case NSUrlErrorExtended.NoPermissionsToReadFile: case NSUrlErrorExtended.CannotLoadFromNetwork: case NSUrlErrorExtended.CannotCreateFile: case NSUrlErrorExtended.CannotOpenFile: case NSUrlErrorExtended.CannotCloseFile: case NSUrlErrorExtended.CannotWriteToFile: case NSUrlErrorExtended.CannotRemoveFile: case NSUrlErrorExtended.CannotMoveFile: case NSUrlErrorExtended.DownloadDecodingFailedMidStream: case NSUrlErrorExtended.DownloadDecodingFailedToComplete: webExceptionStatus = WebExceptionStatus.ReceiveFailure; break; case NSUrlErrorExtended.SecureConnectionFailed: webExceptionStatus = WebExceptionStatus.SecureChannelFailure; break; case NSUrlErrorExtended.ServerCertificateHasBadDate: case NSUrlErrorExtended.ServerCertificateHasUnknownRoot: case NSUrlErrorExtended.ServerCertificateNotYetValid: case NSUrlErrorExtended.ServerCertificateUntrusted: case NSUrlErrorExtended.ClientCertificateRejected: case NSUrlErrorExtended.ClientCertificateRequired: webExceptionStatus = WebExceptionStatus.TrustFailure; break; } goto done; } if (error.Domain == CFNetworkError.ErrorDomain) { // Convert the error code into an enumeration (this is future // proof, rather than just casting integer) CFNetworkErrors networkError; if (!Enum.TryParse<CFNetworkErrors>(error.Code.ToString(), out networkError)) { networkError = CFNetworkErrors.CFHostErrorUnknown; } // Parse the enum into a web exception status or exception. Some // of these values don't necessarily translate completely to // what WebExceptionStatus supports, so made some best guesses // here. For your reading pleasure, compare these: // // Apple docs: https://developer.apple.com/library/ios/documentation/Networking/Reference/CFNetworkErrors/#//apple_ref/c/tdef/CFNetworkErrors // .NET docs: http://msdn.microsoft.com/en-us/library/system.net.webexceptionstatus(v=vs.110).aspx switch (networkError) { case CFNetworkErrors.CFURLErrorCancelled: case CFNetworkErrors.CFURLErrorUserCancelledAuthentication: case CFNetworkErrors.CFNetServiceErrorCancel: // No more processing is required so just return. return new OperationCanceledException(error.LocalizedDescription, innerException); case CFNetworkErrors.CFSOCKS5ErrorBadCredentials: case CFNetworkErrors.CFSOCKS5ErrorUnsupportedNegotiationMethod: case CFNetworkErrors.CFSOCKS5ErrorNoAcceptableMethod: case CFNetworkErrors.CFErrorHttpAuthenticationTypeUnsupported: case CFNetworkErrors.CFErrorHttpBadCredentials: case CFNetworkErrors.CFErrorHttpBadURL: case CFNetworkErrors.CFURLErrorBadURL: case CFNetworkErrors.CFURLErrorUnsupportedURL: case CFNetworkErrors.CFURLErrorCannotConnectToHost: case CFNetworkErrors.CFURLErrorResourceUnavailable: case CFNetworkErrors.CFURLErrorNotConnectedToInternet: case CFNetworkErrors.CFURLErrorUserAuthenticationRequired: case CFNetworkErrors.CFURLErrorInternationalRoamingOff: case CFNetworkErrors.CFURLErrorCallIsActive: case CFNetworkErrors.CFURLErrorDataNotAllowed: webExceptionStatus = WebExceptionStatus.ConnectFailure; break; case CFNetworkErrors.CFURLErrorTimedOut: case CFNetworkErrors.CFNetServiceErrorTimeout: webExceptionStatus = WebExceptionStatus.Timeout; break; case CFNetworkErrors.CFHostErrorHostNotFound: case CFNetworkErrors.CFURLErrorCannotFindHost: case CFNetworkErrors.CFURLErrorDNSLookupFailed: case CFNetworkErrors.CFNetServiceErrorDNSServiceFailure: webExceptionStatus = WebExceptionStatus.NameResolutionFailure; break; case CFNetworkErrors.CFURLErrorDataLengthExceedsMaximum: webExceptionStatus = WebExceptionStatus.MessageLengthLimitExceeded; break; case CFNetworkErrors.CFErrorHttpConnectionLost: case CFNetworkErrors.CFURLErrorNetworkConnectionLost: webExceptionStatus = WebExceptionStatus.ConnectionClosed; break; case CFNetworkErrors.CFErrorHttpRedirectionLoopDetected: case CFNetworkErrors.CFURLErrorHTTPTooManyRedirects: case CFNetworkErrors.CFURLErrorRedirectToNonExistentLocation: webExceptionStatus = WebExceptionStatus.ProtocolError; break; case CFNetworkErrors.CFSOCKSErrorUnknownClientVersion: case CFNetworkErrors.CFSOCKSErrorUnsupportedServerVersion: case CFNetworkErrors.CFErrorHttpParseFailure: case CFNetworkErrors.CFURLErrorRequestBodyStreamExhausted: webExceptionStatus = WebExceptionStatus.SendFailure; break; case CFNetworkErrors.CFSOCKS4ErrorRequestFailed: case CFNetworkErrors.CFSOCKS4ErrorIdentdFailed: case CFNetworkErrors.CFSOCKS4ErrorIdConflict: case CFNetworkErrors.CFSOCKS4ErrorUnknownStatusCode: case CFNetworkErrors.CFSOCKS5ErrorBadState: case CFNetworkErrors.CFSOCKS5ErrorBadResponseAddr: case CFNetworkErrors.CFURLErrorBadServerResponse: case CFNetworkErrors.CFURLErrorZeroByteResource: case CFNetworkErrors.CFURLErrorCannotDecodeRawData: case CFNetworkErrors.CFURLErrorCannotDecodeContentData: case CFNetworkErrors.CFURLErrorCannotParseResponse: case CFNetworkErrors.CFURLErrorFileDoesNotExist: case CFNetworkErrors.CFURLErrorFileIsDirectory: case CFNetworkErrors.CFURLErrorNoPermissionsToReadFile: case CFNetworkErrors.CFURLErrorCannotLoadFromNetwork: case CFNetworkErrors.CFURLErrorCannotCreateFile: case CFNetworkErrors.CFURLErrorCannotOpenFile: case CFNetworkErrors.CFURLErrorCannotCloseFile: case CFNetworkErrors.CFURLErrorCannotWriteToFile: case CFNetworkErrors.CFURLErrorCannotRemoveFile: case CFNetworkErrors.CFURLErrorCannotMoveFile: case CFNetworkErrors.CFURLErrorDownloadDecodingFailedMidStream: case CFNetworkErrors.CFURLErrorDownloadDecodingFailedToComplete: case CFNetworkErrors.CFHTTPCookieCannotParseCookieFile: case CFNetworkErrors.CFNetServiceErrorUnknown: case CFNetworkErrors.CFNetServiceErrorCollision: case CFNetworkErrors.CFNetServiceErrorNotFound: case CFNetworkErrors.CFNetServiceErrorInProgress: case CFNetworkErrors.CFNetServiceErrorBadArgument: case CFNetworkErrors.CFNetServiceErrorInvalid: webExceptionStatus = WebExceptionStatus.ReceiveFailure; break; case CFNetworkErrors.CFURLErrorServerCertificateHasBadDate: case CFNetworkErrors.CFURLErrorServerCertificateUntrusted: case CFNetworkErrors.CFURLErrorServerCertificateHasUnknownRoot: case CFNetworkErrors.CFURLErrorServerCertificateNotYetValid: case CFNetworkErrors.CFURLErrorClientCertificateRejected: case CFNetworkErrors.CFURLErrorClientCertificateRequired: webExceptionStatus = WebExceptionStatus.TrustFailure; break; case CFNetworkErrors.CFURLErrorSecureConnectionFailed: webExceptionStatus = WebExceptionStatus.SecureChannelFailure; break; case CFNetworkErrors.CFErrorHttpProxyConnectionFailure: case CFNetworkErrors.CFErrorHttpBadProxyCredentials: case CFNetworkErrors.CFErrorPACFileError: case CFNetworkErrors.CFErrorPACFileAuth: case CFNetworkErrors.CFErrorHttpsProxyConnectionFailure: case CFNetworkErrors.CFStreamErrorHttpsProxyFailureUnexpectedResponseToConnectMethod: webExceptionStatus = WebExceptionStatus.RequestProhibitedByProxy; break; } goto done; } done: // Always create a WebException so that it can be handled by the client. ret = new WebException(error.LocalizedDescription, innerException, webExceptionStatus, response: null); return ret; }
public static bool IsENException(this NSErrorException nsErrorException) => nsErrorException.Domain == ENErrorDomain;
void HandleUnsubscribeError (NSErrorException ex) { var error = ex.Error; var errorResult = HandleError (error); switch (errorResult) { case Error.Retry: Utils.Retry (ToggleSubscription, error); break; case Error.Ignore: Console.WriteLine ("Ignored error while deleting subscription: {0}", error.Description); break; default: throw new NotImplementedException (); } }