What about throw ex? With Api Response

In my case I have a httpresponse that doesn't fail to make a response but fails to get the results which in turn doesnt map out to the model. This mapping is a soft rule, where something might map and if they don't the api says why. In that case its a 200 response code and I don't get an exception either. 


 public bool SubmitOrder(Order objOrder, ref int iID, ref OrderResponse objOrderResponse, ref string sRtnMsg) {

            try {

                var contJson = JsonConvert.SerializeObject(objOrder);

                var jsFormatted = JToken.Parse(contJson).ToString(Formatting.Indented);

                Log.Trace("Submitting Order: With {0}", jsFormatted);

                var flagError = false;

                var error = "";

                var accessToken = GetToken();

                Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);

                HttpRequestMessage requestNew = new HttpRequestMessage(HttpMethod.Post, "{url}/api/Token/") {

                    Content = new StringContent(JsonConvert.SerializeObject(objOrder), Encoding.UTF8, "application/json")


                var postOrder = Task.Run(() => Client.PostAsync("{url}/", requestNew.Content)

                                                     .ContinueWith(responseTask => {

                                                         var contJsonReturn = JsonConvert.SerializeObject(responseTask.Result.Content.ReadAsStringAsync().Result);

                                                         var jsFormattedReturn = JToken.Parse(contJsonReturn).ToString(Formatting.Indented);

                                                         Log.Trace("Returned Order: With {0}", responseTask.Result.Content,


                                                         if (!responseTask.Result.IsSuccessStatusCode) {

                                                             error = responseTask.Result.Content.ReadAsStringAsync().Result;


                                                             flagError = true;


                                                         return responseTask.Result.Content.ReadAsAsync<OrderResponse>(new[] { new JsonMediaTypeFormatter() }).Result;



                if (!flagError) {

                    iID = postOrder.Result.ReadOnly.OrderId;

                    objOrderResponse = postOrder.Result;

                    return true;

                    } else {

                    sRtnMsg = JsonConvert.SerializeObject(new { error = error });

                    return false;



                } catch (Exception ex) {


                sRtnMsg = ex.Message;

                return false;




Popular posts from this blog

Installing Windows on Acer chromebook 15 cb3-532

Entity Framework: ToListAynsc & WhereAsync

CSharp Cheatsheet