Пример #1
0
        public Task <IResponse> Execute(HttpMethod method, string uriTemplate, IDictionary <string, object> parameters,
                                        IDictionary <string, string> headers, object body)
        {
            if (Exception != null)
            {
                throw Exception;
            }

            try
            {
                var response = Response;
                if (response.StatusCode >= 200 && response.StatusCode < 300)
                {
                    return(Task.FromResult(response));
                }
                throw ServiceException.FromResponse(response);
            }
            catch (ServiceException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new ServiceException("Request failed", null, e);
            }
        }
Пример #2
0
        public void TestRaisesServiceException()
        {
            var response = new Response(401, "{\"error\":{\"message\":\"Unauthorized\"}}");
            var ex       = ServiceException.FromResponse(response);

            Assert.NotNull(ex);
            Assert.AreEqual("Unauthorized", ex.Message);
        }
Пример #3
0
        public void TestRaisesServiceExceptionWithoutBody()
        {
            var httpResponse = FromFile("ping.unauthorized");
            var response     = new Response(httpResponse);
            var ex           = ServiceException.FromResponse(response);

            Assert.NotNull(ex);
            Assert.AreEqual("Request failed", ex.Message);
        }
Пример #4
0
        public void TestRaisesServiceExceptionFromFile()
        {
            var httpResponse = FromFile("me.unauthorized");
            var response     = new Response(httpResponse);
            var ex           = ServiceException.FromResponse(response);

            Assert.NotNull(ex);
            Assert.AreEqual("Unauthorized", ex.Message);
        }