示例#1
0
        public async Task <TfLRoadCorridors> GetRoadStatusData(string roadNames)
        {
            string requestUri = BuildRequestUri(roadNames);

            var httpResponse = await _httpClient.GetAsync(requestUri);

            string response = await httpResponse.Content.ReadAsStringAsync();

            if (httpResponse.IsSuccessStatusCode)
            {
                List <TfLRoadCorridor> responseData = JsonConvert.DeserializeObject <List <TfLRoadCorridor> >(response);
                return(new TfLRoadCorridors(responseData));
            }
            else
            {
                if (httpResponse.StatusCode == System.Net.HttpStatusCode.NotFound)
                {
                    TfLApiError responseError = JsonConvert.DeserializeObject <TfLApiError>(response);
                    throw new TfLApiException(responseError);
                }
                else
                {
                    throw new Exception($"Something went wrong calling external api. Status Code: {httpResponse.StatusCode}.");
                }
            }
        }
示例#2
0
        private TfLApiException NotFoundException()
        {
            TfLApiError apiError = new TfLApiError()
            {
                ExceptionType  = "EntityNotFoundException",
                HttpStatusCode = 404,
                HttpStatus     = "NotFound",
                RelativeUri    = "/Road/A233",
                Message        = "The following road id is not recognised: A233"
            };

            return(new TfLApiException(apiError));
        }