Exemplo n.º 1
0
        internal async Task <BuddyResult <T> > HandleServiceResult <T>(BuddyCallResult <T> serviceResult, bool allowThrow = false)
        {
            var result = new BuddyResult <T> ();

            result.RequestID = serviceResult.RequestID;
            if (serviceResult.Error != null)
            {
                BuddyServiceException buddyException = null;
                switch (serviceResult.StatusCode)
                {
                case 0:
                    buddyException = new BuddyNoInternetException(serviceResult.Error);
                    break;

                case 401:
                case 403:
                    buddyException = new BuddyUnauthorizedException(serviceResult.Error, serviceResult.Message, serviceResult.ErrorNumber);
                    break;

                default:
                    buddyException = new BuddySDK.BuddyServiceException(serviceResult.Error, serviceResult.Message, serviceResult.ErrorNumber);
                    break;
                }
                TaskCompletionSource <bool> uiPromise = new TaskCompletionSource <bool> ();
                PlatformAccess.Current.InvokeOnUiThread(async() => {
                    var r = false;
                    if (await OnServiceException(this, buddyException))
                    {
                        r = true;
                    }
                    uiPromise.TrySetResult(r);
                });
                if (await uiPromise.Task && allowThrow)
                {
                    throw buddyException;
                }
                buddyException.StatusCode = serviceResult.StatusCode;
                result.Error = buddyException;
            }
            else
            {
                result.Value = serviceResult.Result;
            }
            return(result);
        }
Exemplo n.º 2
0
        protected async Task <bool> OnServiceException(BuddyClient client, BuddyServiceException buddyException)
        {
            if (buddyException is BuddyUnauthorizedException)
            {
                client.OnAuthorizationFailure((BuddyUnauthorizedException)buddyException);
                return(false);
            }
            else if (buddyException is BuddyNoInternetException)
            {
                await client.OnConnectivityChanged(ConnectivityLevel.None);

                return(false);
            }

            bool result = false;

            if (ServiceException != null)
            {
                var args = new ServiceExceptionEventArgs(buddyException);
                ServiceException(this, args);
                result = args.ShouldThrow;
            }
            return(result);
        }
 public ServiceExceptionEventArgs(BuddyServiceException ex)
 {
     Exception = ex;
 }
 public ServiceExceptionEventArgs(BuddyServiceException ex) {
     Exception = ex;
 }
Exemplo n.º 5
0
 internal BuddyResult(string requestId, BuddyServiceException error) :
     base(requestId, error)
 {
 }
Exemplo n.º 6
0
 internal BuddyResultBase(string requestId, BuddyServiceException error)
 {
     RequestID = requestId;
     Error     = error;
 }