예제 #1
0
        public CreatedResult GetError500_InternalServerError(string transactionID, string errorMessage, string errorInternal, string route)
        {
            /*General_500ErrorResponse general_500ErrorResponse = new General_500ErrorResponse();
             * general_500ErrorResponse.TransactionID = transactionID;
             * general_500ErrorResponse.Error = errorMessage;
             * general_500ErrorResponse.Route = route;
             * general_500ErrorResponse.ErrorInternal = null;
             *
             * GeneralErrorResponseContainer generalErrorResponseContainer = new GeneralErrorResponseContainer();
             * generalErrorResponseContainer.Warning = System.Net.HttpStatusCode.InternalServerError.ToString();
             * generalErrorResponseContainer.ErrorResponse = general_500ErrorResponse;
             * CreatedResult createdResult = new CreatedResult(route, null);
             * createdResult.StatusCode = 500;
             * createdResult.Value = generalErrorResponseContainer;
             * return createdResult;*/

            GeneralErrorResponse general_500ErrorResponse = new GeneralErrorResponse();

            general_500ErrorResponse.TransactionID = transactionID;
            general_500ErrorResponse.Error         = errorMessage;
            general_500ErrorResponse.Route         = route;
            general_500ErrorResponse.ErrorInternal = errorInternal;
            GeneralErrorResponseContainer generalErrorResponseContainer = new GeneralErrorResponseContainer();

            generalErrorResponseContainer.Warning       = System.Net.HttpStatusCode.PreconditionFailed.ToString();
            generalErrorResponseContainer.ErrorResponse = general_500ErrorResponse;
            CreatedResult createdResult = new CreatedResult(route, null);

            createdResult.StatusCode = 412;
            createdResult.Value      = generalErrorResponseContainer;
            return(createdResult);
        }
예제 #2
0
        public CreatedResult GetError412_PreConditionFailed(string transactionID, string errorMessage, string errorInternal, string route)
        {
            GeneralErrorResponse general_412ErrorResponse = new GeneralErrorResponse();

            general_412ErrorResponse.TransactionID = transactionID;
            general_412ErrorResponse.Error         = errorMessage;
            general_412ErrorResponse.Route         = route;
            general_412ErrorResponse.ErrorInternal = errorInternal;
            GeneralErrorResponseContainer generalErrorResponseContainer = new GeneralErrorResponseContainer();

            generalErrorResponseContainer.Warning       = System.Net.HttpStatusCode.PreconditionFailed.ToString();
            generalErrorResponseContainer.ErrorResponse = general_412ErrorResponse;
            CreatedResult createdResult = new CreatedResult(route, null);

            createdResult.StatusCode = 412;
            createdResult.Value      = generalErrorResponseContainer;
            return(createdResult);
        }
예제 #3
0
        public void ParseError(string responseString, HttpResponseMessage response, out string error, out GeneralPostResponse generalPostResponse, out GeneralErrorResponseContainer generalErrorResponse)
        {
            generalErrorResponse = null;
            generalPostResponse  = null;
            error = null;
            if (response == null)
            {
                error = "Catastrophic error. No HttpResponse from server.";
                return;
            }
            else
            {
                if (string.IsNullOrEmpty(responseString))
                {
                    error = "Catastrophic error. No body from server.";
                    return;
                }

                if (response.IsSuccessStatusCode)
                {
                    generalPostResponse = JsonConvert.DeserializeObject <GeneralPostResponse>(responseString);
                }
                else
                {
                    try
                    {
                        generalErrorResponse = JsonConvert.DeserializeObject <GeneralErrorResponseContainer>(responseString);
                        string formatedError = "Error:{0} Internal:{1} Route:{2} TransactionID:{3}";
                        formatedError = string.Format(formatedError,
                                                      generalErrorResponse.ErrorResponse.Error,
                                                      generalErrorResponse.ErrorResponse.ErrorInternal,
                                                      generalErrorResponse.ErrorResponse.Route,
                                                      generalErrorResponse.ErrorResponse.TransactionID);
                        error = formatedError;
                    }
                    catch (Exception ex)
                    {
                        error = "Catastrophic 2 errors: Served crashed(1) and Client(2) can't deserialize json. Original json from server is:" + responseString;
                    }
                }
            }
        }