public T MapStream <T>(Stream requestStream) { var strResponse = new StreamReader(requestStream).ReadToEnd(); int jsonStart = strResponse.IndexOf('{'); int jsonEnd = strResponse.LastIndexOf('}') + 1; var strJsonResponse = strResponse.Substring(jsonStart, jsonEnd - jsonStart);//.Replace("\\", ""); //remove callback({someJson}); try { JObject jResponse = null; try { jResponse = JsonConvert.DeserializeObject <JObject>(strJsonResponse); } catch { strJsonResponse = strResponse.Substring(jsonStart, jsonEnd - jsonStart); jResponse = JsonConvert.DeserializeObject <JObject>(strJsonResponse); } if (jResponse.Properties().Any(p => p.Name == "error") && (int)jResponse["error"]["code"] != 81520) { var errorData = new BusinessCoreExceptionData { Code = (int)jResponse["error"]["code"], Message = (string)jResponse["error"]["message"], StackTrace = (string)jResponse["error"]["stack trace"] }; throw new BusinessCoreException(typeof(IFasAgent), errorData.Message, errorData); } return(jResponse.ToObject <T>()); } catch (JsonReaderException ex) { throw new BusinessCoreException(typeof(IFasAgent), "Response returned from FAS is not valid JSON:\n" + strResponse, ex); } }
public BusinessCoreException(Type typeOfAgent, string message, Exception innerException, BusinessCoreExceptionData errorData = null) : base(message, innerException) { _typeOfAgent = typeOfAgent; _errorData = errorData; }