Exemple #1
0
        /// <summary>
        /// Process the error response.
        /// </summary>
        private async Task <Exception> ProcessDownloadErrorResponse(Exception exception)
        {
            Exception error;

            try
            {
                IInputStream responseStream = this.downloadOperation.GetResultStreamAt(0);
                if (responseStream == null)
                {
                    error = new LiveConnectException(
                        ApiOperation.ApiServerErrorCode,
                        ResourceHelper.GetString("ConnectionError"));
                }
                else
                {
                    var  reader = new DataReader(responseStream);
                    uint length = await reader.LoadAsync(MaxDownloadResponseLength);

                    error = ApiOperation.CreateOperationResultFrom(reader.ReadString(length), ApiMethod.Download).Error;
                    if (error is FormatException)
                    {
                        // if we cannot understand the error response,
                        // return the exception thrown by the background downloader.
                        error = exception;
                    }
                }
            }
            catch (COMException exp)
            {
                error = exp;
            }
            catch (FileNotFoundException exp)
            {
                error = exp;
            }

            return(error);
        }
Exemple #2
0
            public void OnErrorResponse(string code, string message)
            {
                var error = new LiveConnectException(code, message);

                this.Result = new LiveOperationResult(error, false);
            }
 private static void ValidateError(LiveConnectException error, string expectedCode)
 {
     Assert.IsTrue(error.ErrorCode.Equals(expectedCode, StringComparison.Ordinal), "Unexpected error code.  Expect: " + expectedCode + " Actual: " + error.ErrorCode);
     Assert.IsTrue(!string.IsNullOrEmpty(error.Message));
 }
        /// <summary>
        /// Process the error response.
        /// </summary>
        private async Task<Exception> ProcessDownloadErrorResponse(Exception exception)
        {
            Exception error;
            try
            {
                IInputStream responseStream = this.downloadOperation.GetResultStreamAt(0);
                if (responseStream == null)
                {
                    error = new LiveConnectException(
                        ApiOperation.ApiServerErrorCode,
                        ResourceHelper.GetString("ConnectionError"));
                }
                else
                {
                    var reader = new DataReader(responseStream);
                    uint length = await reader.LoadAsync(MaxDownloadResponseLength);
                    error = ApiOperation.CreateOperationResultFrom(reader.ReadString(length), ApiMethod.Download).Error;
                    if (error is FormatException)
                    {
                        // if we cannot understand the error response,
                        // return the exception thrown by the background downloader.
                        error = exception;
                    }
                }
            }
            catch (COMException exp)
            {
                error = exp;
            }
            catch (FileNotFoundException exp)
            {
                error = exp;
            }

            return error;
        }
 public void OnErrorResponse(string code, string message)
 {
     var error = new LiveConnectException(code, message);
     this.Result = new LiveOperationResult(error, false);
 }