예제 #1
0
 public BaseResponse(RespsonseStatus status = RespsonseStatus.Ok, ResponseError error = ResponseError.None,
     string errorMessage = "")
 {
     Status = status;
     ErrorCode = error;
     ErrorMessage = errorMessage;
 }
        /// <summary>
        /// Deserialize items from byte array.
        /// </summary>
        /// <param name="byteArray">The byte array which contains response message.</param>
        /// <param name="currentIndex">The index special where to start.</param>
        /// <param name="lengthOfItems">The length of items.</param>
        protected override void DeserializeItemsFromByteArray(byte[] byteArray, ref int currentIndex, int lengthOfItems)
        {
            if (lengthOfItems != 0)
            {
                throw new ResponseParseErrorException(currentIndex, "ReadAccessResponse over-parse error", null);
            }

            int index = currentIndex;
            this.ReadResponseError = StreamObject.GetCurrent<ResponseError>(byteArray, ref index);
            currentIndex = index;
        }
예제 #3
0
        /// <summary>
        /// Creates the error response from the values provided.
        /// 
        /// If the errorCode is empty it will use the first validation error code, 
        /// if there is none it will throw an error.
        /// </summary>
        /// <param name="errorCode">The error code.</param>
        /// <param name="errorMessage">The error message.</param>
        /// <param name="validationErrors">The validation errors.</param>
        /// <returns></returns>
        public static ResponseStatus CreateResponseStatus(string errorCode, string errorMessage, IEnumerable<ValidationErrorField> validationErrors)
        {
            var to = new ResponseStatus {
                ErrorCode = errorCode,
                Message = errorMessage,
                Errors = new List<ResponseError>(),
            };
            if (validationErrors != null)
            {
                foreach (var validationError in validationErrors)
                {
                    var error = new ResponseError {
                        ErrorCode = validationError.ErrorCode,
                        FieldName = validationError.FieldName,
                        Message = validationError.ErrorMessage,
                    };
                    to.Errors.Add(error);

                    if (string.IsNullOrEmpty(to.ErrorCode))
                    {
                        to.ErrorCode = validationError.ErrorCode;
                    }
                    if (string.IsNullOrEmpty(to.Message))
                    {
                        to.Message = validationError.ErrorMessage;
                    }
                }
            }
            if (string.IsNullOrEmpty(errorCode))
            {
                if (string.IsNullOrEmpty(to.ErrorCode))
                {
                    throw new ArgumentException("Cannot create a valid error response with a en empty errorCode and an empty validationError list");
                }
            }
            return to;
        }
예제 #4
0
 public ServiceException(ResponseError errorCode)
 {
     ErrorCode = errorCode;
 }
예제 #5
0
 public ProtocolException(ResponseError respError, String errorMessage)
     : this(respError.Key, errorMessage, null)
 {
 }
예제 #6
0
 /// <summary>
 /// Occurs when a response returns an error code that does not fit into any other category, or an exception occurs during the response.
 /// </summary>
 /// <param name="e">Arguments for the event.</param>
 protected virtual void OnResponseError(ResponseEventArgs e)
 {
     ResponseError?.Invoke(this, e);
 }
예제 #7
0
 public void SetError(ResponseError error, string errorMessage)
 {
     SetError(error);
     ErrorMessage = errorMessage;
 }
        /// <summary>
        /// This method is used to test Response Error related adapter requirements.
        /// </summary>
        /// <param name="instance">Specify the instance which need to be verified.</param>
        /// <param name="site">Specify the ITestSite instance.</param>
        public void VerifyResponseError(ResponseError instance, ITestSite site)
        {
            // If the instance is not null and there are no parsing errors, then the Response Error related adapter requirements can be directly captured.
            if (null == instance)
            {
                site.Assert.Fail("The instance of type ResponseError is null due to parsing error or type casting error.");
            }

            // Verify the stream object header related requirements.
            this.ExpectStreamObjectHeaderStart(instance.StreamObjectHeaderStart, instance.GetType(), site);

            // Directly capture requirement MS-FSSHTTPB_R617, if the stream object header is StreamObjectHeaderStart32bit.
            site.CaptureRequirementIfAreEqual<Type>(
                     typeof(StreamObjectHeaderStart32bit),
                     instance.StreamObjectHeaderStart.GetType(),
                     "MS-FSSHTTPB",
                     617,
                     @"[In Response Error] Error Start (4 bytes): A 32-bit stream object header (section 2.2.1.5.2) that specifies an error start.");

            // Directly capture requirement MS-FSSHTTPB_R618, if there are no parsing errors. 
            site.CaptureRequirement(
                     "MS-FSSHTTPB",
                     618,
                     @"[In Response Error] Error Type GUID (16 bytes): A GUID that specifies the error type.");

            bool responseErrorFlag = instance.ErrorTypeGUID == new Guid(ResponseError.CellErrorGuid)
                                   || instance.ErrorTypeGUID == new Guid(ResponseError.ProtocolErrorGuid)
                                   || instance.ErrorTypeGUID == new Guid(ResponseError.Win32ErrorGuid)
                                   || instance.ErrorTypeGUID == new Guid(ResponseError.HresultErrorGuid);

            site.Assert.IsTrue(
                        responseErrorFlag,
                        "Actual the error type guid {0}, which should be either 5A66A756-87CE-4290-A38B-C61C5BA05A67,7AFEAEBF-033D-4828-9C31-3977AFE58249, 32C39011-6E39-46C4-AB78-DB41929D679E or 8454C8F2-E401-405A-A198-A10B6991B56E for requirement MS-FSSHTTPB_R619",
                        instance.ErrorTypeGUID.ToString());

            // Directly capture requirement MS-FSSHTTPB_R619, if the responseErrorFlag is true;
            site.CaptureRequirementIfIsTrue(
                     responseErrorFlag,
                     "MS-FSSHTTPB",
                     619,
                     @"[In Response Error] Error Type GUID (16 bytes): The following table contains the possible values for the error type: [the value of the Error Type GUID field must be {5A66A756-87CE-4290-A38B-C61C5BA05A67},{7AFEAEBF-033D-4828-9C31-3977AFE58249}, {32C39011-6E39-46C4-AB78-DB41929D679E}, {8454C8F2-E401-405A-A198-A10B6991B56E}.");

            switch (instance.ErrorTypeGUID.ToString("D").ToUpper(CultureInfo.CurrentCulture))
            {
                case ResponseError.CellErrorGuid:

                    // Capture requirement MS-FSSHTTPB_R620, if the error data type is CellError. 
                    site.CaptureRequirementIfAreEqual<Type>(
                             typeof(CellError),
                             instance.ErrorData.GetType(),
                             "MS-FSSHTTPB",
                             620,
                             @"[In Response Error] Error Type GUID field is set to {5A66A756-87CE-4290-A38B-C61C5BA05A67}[ specifies the error type is ]Cell error (section 2.2.3.2.1).");

                    break;

                case ResponseError.ProtocolErrorGuid:

                    // All the serial number null values related requirements can be located here.
                    site.Log.Add(LogEntryKind.Debug, "Runs for ProtocolErrorGuid verification logic with the error code {0}.", instance.ErrorData.ErrorDetail);
                    break;

                case ResponseError.Win32ErrorGuid:

                    // Capture requirement MS-FSSHTTPB_R622, if the error data type is Win32 error. 
                    site.CaptureRequirementIfAreEqual<Type>(
                             typeof(Win32Error),
                             instance.ErrorData.GetType(),
                             "MS-FSSHTTPB",
                             622,
                             @"[In Response Error] Error Type GUID field is set to {32C39011-6E39-46C4-AB78-DB41929D679E}[ specifies the error type is ]Win32 error (section 2.2.3.2.3).");

                    break;

                case ResponseError.HresultErrorGuid:

                    // Capture requirement MS-FSSHTTPB_R623, if the error data type is HRESULTError.  
                    site.CaptureRequirementIfAreEqual<Type>(
                             typeof(HRESULTError),
                             instance.ErrorData.GetType(),
                             "MS-FSSHTTPB",
                             623,
                             @"[In Response Error] Error Type GUID field is set to {8454C8F2-E401-405A-A198-A10B6991B56E}[ specifies the error type is ]HRESULT error (section 2.2.3.2.4).");

                    break;

                default:
                    site.Assert.Fail("Unsupported error type GUID " + instance.ErrorTypeGUID.ToString());
                    break;
            }

            // Directly capture requirement MS-FSSHTTPB_R625, if there are no parsing errors. 
            site.CaptureRequirement(
                     "MS-FSSHTTPB",
                     625,
                     @"[In Response Error] Error Data (variable): A structure that specifies the error data based on the Error Type GUID.");

            if (instance.ChainedError != null)
            {
                // Directly capture requirement MS-FSSHTTPB_R631, if there are no parsing errors. 
                site.CaptureRequirement(
                         "MS-FSSHTTPB",
                         631,
                         @"[In Response Error] Chained Error (variable): An optional response error that specifies the chained error information.");
            }

            // Verify the stream object header end related requirements.
            this.ExpectStreamObjectHeaderEnd(instance.StreamObjectHeaderEnd, instance.GetType(), site);
            this.ExpectCompoundObject(instance.StreamObjectHeaderStart, site);

            // Directly capture requirement MS-FSSHTTPB_R632, if the stream object end is StreamObjectHeaderEnd16bit.
            site.CaptureRequirementIfAreEqual<Type>(
                     typeof(StreamObjectHeaderEnd16bit),
                     instance.StreamObjectHeaderEnd.GetType(),
                     "MS-FSSHTTPB",
                     632,
                     @"[In Response Error] Error End (2 bytes): A 16-bit stream object header (section 2.2.1.5.4) that specifies an error end.");
        }
예제 #9
0
 public JsonRpcRemoteException(ResponseError error)
     : this(error?.Message, error, null)
 {
     Initialize();
 }
예제 #10
0
 public JsonRpcRemoteException(string message, ResponseError error, Exception innerException)
     : base(message, innerException)
 {
     Error = error;
 }
예제 #11
0
 internal ErrorResponse(ResponseError error)
 {
     Error = error;
 }
 protected virtual bool TryHandleBusinessExceptionByPayload(ResponseError error, out Exception generatedException)
 {
     generatedException = null;
     return(false);
 }
예제 #13
0
        private void SelectPlayer(Grant grant, List <LootLockerRewardObject> rewardObjects = null)
        {
            string header                    = "";
            string normalTextMessage         = "";
            Dictionary <string, string> data = new Dictionary <string, string>();
            string icon = grant == Grant.Credits ? creditsSprite : xpSprite;

            LootLockerSDKManager.StartSession(LootLockerConfig.current.deviceID, (response) =>
            {
                LoadingManager.HideLoadingScreen();
                if (response.success)
                {
                    header = "Success";

                    if (grant == Grant.Credits)
                    {
                        normalTextMessage = "Successfully granted Credits.";
                    }
                    if (grant == Grant.XP)
                    {
                        normalTextMessage = "Successfully granted XP.";
                    }

                    data.Clear();
                    //Preparing data to display or error messages we have
                    data.Add("1", normalTextMessage);
                    StagesManager.instance.GoToStage(StagesManager.StageID.Home, response);
                    if (rewardObjects != null && rewardObjects.Count > 0)
                    {
                        for (int i = 0; i < rewardObjects.Count; i++)
                        {
                            PopupData PopupData  = new PopupData();
                            PopupData.buttonText = "Ok";
                            PopupData.url        = rewardObjects[i].asset.links.thumbnail;
                            PopupData.withKey    = true;
                            PopupData.normalText = new Dictionary <string, string>()
                            {
                                { "Reward", rewardObjects[i].asset.name }
                            };
                            PopupData.header = "You got a reward";
                            PopupSystem.ShowScheduledPopup(PopupData);
                        }
                    }
                }
                else
                {
                    header = "Failed";

                    string correctedResponse   = response.Error.First() == '{' ? response.Error : response.Error.Substring(response.Error.IndexOf('{'));
                    ResponseError errorMessage = new ResponseError();
                    errorMessage = JsonConvert.DeserializeObject <ResponseError>(correctedResponse);

                    normalTextMessage = errorMessage.messages[0];

                    data.Clear();
                    //Preparing data to display or error messages we have
                    data.Add("1", normalTextMessage);
                }
                PopupSystem.ShowApprovalFailPopUp(header, data, icon);
            });
        }
예제 #14
0
 public Status(ResponseError responseError)
 {
     CODE = responseError.CODE;
     DESC = responseError.DESC;
 }
예제 #15
0
 public SocialSpiException(ResponseError error, String errorMessage)
     : base(errorMessage)
 {
     this.error = error;
 }
예제 #16
0
 void Instance_onEncounterError(ResponseError data)
 {
     if(data.showPopup)
         DialogService.Instance.ShowDialog(new DialogMessage("Error: " + data.errorCode, data.errorMessage, null));
 }
예제 #17
0
        public void ProcessSubscriptionStatus(Session session, Message message)
        {
            IObserver <SubscriptionResponse> observer;

            if (!TryGet(message.CorrelationID, out observer))
            {
                return;
            }

            if (MessageTypeNames.SubscriptionFailure.Equals(message.MessageType))
            {
                var reasonElement = message.GetElement(ElementNames.Reason);
                var error         = new ResponseError(
                    reasonElement.GetElement(ElementNames.Source).GetValueAsString(),
                    reasonElement.GetElement(ElementNames.Category).GetValueAsString(),
                    null,
                    reasonElement.GetElement(ElementNames.ErrorCode).GetValueAsInt32(),
                    reasonElement.GetElement(ElementNames.Description).GetValueAsString());
                var subscriptionFailure = new SubscriptionFailure(error);
                observer.OnNext(new SubscriptionResponse(message.TopicName, subscriptionFailure));
            }
            else if (MessageTypeNames.SubscriptionTerminated.Equals(message.MessageType))
            {
                var reason = message.GetElement(ElementNames.Reason);
                switch (reason.GetElementAsString(ElementNames.Category))
                {
                case "LIMIT":
                    var responseError = new ResponseError(
                        reason.GetElement(ElementNames.Source).GetValueAsString(),
                        reason.GetElement(ElementNames.Category).GetValueAsString(),
                        null,
                        reason.GetElement(ElementNames.ErrorCode).GetValueAsInt32(),
                        reason.GetElement(ElementNames.Description).GetValueAsString());
                    observer.OnNext(new SubscriptionResponse(message.TopicName, new SubscriptionFailure(responseError)));
                    break;

                case "UNCLASSIFIED":
                    /*
                     * "Failed to obtain initial paint"
                     * If this error occurs, the Bloomberg Data Center
                     * was unable to get the initial paint for the
                     * subscription. You will still receive subscription
                     * ticks.
                     */
                    break;

                case "CANCELED":
                    Remove(message.CorrelationID);
                    observer.OnCompleted();
                    break;
                }
            }
            else if (MessageTypeNames.SubscriptionStarted.Equals(message.MessageType))
            {
                if (message.HasElement(ElementNames.Exceptions))
                {
                    var fieldErrors            = new Dictionary <string, ResponseError>();
                    var exceptionsArrayElement = message.GetElement(ElementNames.Exceptions);
                    for (var i = 0; i < exceptionsArrayElement.NumValues; ++i)
                    {
                        var exceptionsElement = exceptionsArrayElement.GetValueAsElement(i);
                        var fieldId           = exceptionsElement.GetElementAsString(ElementNames.FieldId);
                        var reasonElement     = exceptionsElement.GetElement(ElementNames.Reason);
                        var error             = new ResponseError(
                            reasonElement.GetElement(ElementNames.Source).GetValueAsString(),
                            reasonElement.GetElement(ElementNames.Category).GetValueAsString(),
                            reasonElement.GetElement(ElementNames.SubCategory).GetValueAsString(),
                            reasonElement.GetElement(ElementNames.ErrorCode).GetValueAsInt32(),
                            reasonElement.GetElement(ElementNames.Description).GetValueAsString());
                        fieldErrors.Add(fieldId, error);
                    }
                    var subscriptionFailure = new SubscriptionFailure(fieldErrors);
                    observer.OnNext(new SubscriptionResponse(message.TopicName, subscriptionFailure));
                }
            }
        }
예제 #18
0
 public void SetError(ResponseError error)
 {
     Status = RespsonseStatus.Error;
     ErrorCode = error;
 }
예제 #19
0
        public static async ValueTask <RequestFailedException> CreateExceptionForFailedOperationAsync(bool async, ClientDiagnostics diagnostics, Response response, ResponseError error)
        {
            var additionalInfo = new Dictionary <string, string>(1)
            {
                { "AdditionInformation", error.ToString() }
            };

            return(async
                ? await diagnostics.CreateRequestFailedExceptionAsync(response, error, additionalInfo).ConfigureAwait(false)
                : diagnostics.CreateRequestFailedException(response, error, additionalInfo));
        }
 public TickerResponseError(string ticker, ResponseError responseError)
 {
     Ticker = ticker;
     ResponseError = responseError;
 }
예제 #21
0
        public async Task GetAndListOperationsAsync()
        {
            string endpoint = TestEnvironment.Endpoint;
            string apiKey   = TestEnvironment.ApiKey;

            #region Snippet:FormRecognizerSampleGetAndListOperations

            var client = new DocumentModelAdministrationClient(new Uri(endpoint), new AzureKeyCredential(apiKey));

            // Make sure there is at least one operation, so we are going to build a custom model.
#if SNIPPET
            Uri trainingFileUri = < trainingFileUri >;
#else
            Uri trainingFileUri = new Uri(TestEnvironment.BlobContainerSasUrl);
#endif
            BuildModelOperation operation = await client.StartBuildModelAsync(trainingFileUri, DocumentBuildMode.Template);

            await operation.WaitForCompletionAsync();

            // List the first ten or fewer operations that have been executed in the last 24h.
            AsyncPageable <ModelOperationInfo> modelOperations = client.GetOperationsAsync();

            string operationId = string.Empty;
            int    count       = 0;
            await foreach (ModelOperationInfo modelOperationInfo in modelOperations)
            {
                Console.WriteLine($"Model operation info:");
                Console.WriteLine($"  Id: {modelOperationInfo.OperationId}");
                Console.WriteLine($"  Kind: {modelOperationInfo.Kind}");
                Console.WriteLine($"  Status: {modelOperationInfo.Status}");
                Console.WriteLine($"  Percent completed: {modelOperationInfo.PercentCompleted}");
                Console.WriteLine($"  Created on: {modelOperationInfo.CreatedOn}");
                Console.WriteLine($"  LastUpdated on: {modelOperationInfo.LastUpdatedOn}");
                Console.WriteLine($"  Resource location of successful operation: {modelOperationInfo.ResourceLocation}");

                if (count == 0)
                {
                    operationId = modelOperationInfo.OperationId;
                }

                if (++count == 10)
                {
                    break;
                }
            }

            // Get an operation by ID
            ModelOperation specificOperation = await client.GetOperationAsync(operationId);

            if (specificOperation.Status == DocumentOperationStatus.Succeeded)
            {
                Console.WriteLine($"My {specificOperation.Kind} operation is completed.");
                DocumentModel result = specificOperation.Result;
                Console.WriteLine($"Model ID: {result.ModelId}");
            }
            else if (specificOperation.Status == DocumentOperationStatus.Failed)
            {
                Console.WriteLine($"My {specificOperation.Kind} operation failed.");
                ResponseError error = specificOperation.Error;
                Console.WriteLine($"Code: {error.Code}: Message: {error.Message}");
            }
            else
            {
                Console.WriteLine($"My {specificOperation.Kind} operation status is {specificOperation.Status}");
            }
            #endregion
        }