public void BuildTelnyxException() { var telnyxResponse = new TelnyxResponse() { ObjectJson = "{\"a\":\"x\", \"b\":\"y\", \"z\":\"c\"}", RequestId = "1", RequestDate = DateTime.Now, ResponseJson = "{\"a\":\"x\", \"b\":\"y\", \"z\":\"c\"}", Url = "https://www.example.com" }; //Requestor.BuildTelnyxException(telnyxResponse, HttpStatusCode.BadRequest, "https://www.example.com", ""); }
private static TelnyxResponse BuildResponseData(HttpResponseMessage response, string responseText) { var result = new TelnyxResponse { RequestId = response.Headers.Contains("Request-Id") ? response.Headers.GetValues("Request-Id").First() : "n/a", RequestDate = response.Headers.Contains("Date") ? Convert.ToDateTime(response.Headers.GetValues("Date").First(), CultureInfo.InvariantCulture) : default(DateTime), ResponseJson = responseText, }; return(result); }
public MapperTest() { _stringValue = "TestValue"; _testModel = new TestModel() { Name = _stringValue, Address = _stringValue }; _telnyxResponse = new TelnyxResponse() { ResponseJson = JsonConvert.SerializeObject(_testModel), ObjectJson = _stringValue, RequestId = "Id001", RequestDate = DateTime.Now, Url = "example.com/test" }; }
private static TelnyxException BuildTelnyxException(TelnyxResponse response, HttpStatusCode statusCode, string requestUri, string responseContent) { try { var telnyxErrors = Mapper <IEnumerable <TelnyxError> > .MapFromJsonErrors(responseContent, "errors", response); //todo: double check with API on these fields. seems errors always return as array var message = telnyxErrors.Any() ? (string.Join(" | ", telnyxErrors.Select(x => $"{x.ErrorTitle ?? string.Empty} {x.ErrorDetail ?? string.Empty} {x.ErrorDescription ?? string.Empty} {x.Message ?? string.Empty}"))).Trim() : string.Empty; return(new TelnyxException(statusCode, telnyxErrors, message)); } catch { // TEL29 fix: Errors are not being passed to user return(new TelnyxException(statusCode, new TelnyxError { Message = responseContent, RequestUri = requestUri }, responseContent)); } }