Exemplo n.º 1
0
        public HttpResponse(int?status, Dictionary <string, string> headers, byte[] data, RestliException error)
        {
            this.status  = status;
            this.headers = headers ?? new Dictionary <string, string>();
            this.data    = data;

            this.error = error;
        }
Exemplo n.º 2
0
 private void AddStatusOrHeaderError()
 {
     if (error == null)
     {
         if (headers.ContainsKey(RestConstants.kHeaderRestliErrorResponse))
         {
             error = new RestliException("Server returned Rest.li error response", null);
         }
         else if (status < 200 || status >= 300)
         {
             error = new RestliException(string.Format("Response has HTTP status code {0}", status), null);
         }
     }
 }
        public void GetGreeting_Async_ServerError()
        {
            RestClient client = new RestClient(urlPrefix);

            GetRequestBuilder <int, Greeting> requestBuilder = new GetRequestBuilder <int, Greeting>("/basicCollection");

            requestBuilder.SetID(-1);
            GetRequest <int, Greeting> request = requestBuilder.Build();

            AutoResetEvent blocker = new AutoResetEvent(false);

            Greeting            greeting      = null;
            ClientErrorResponse errorResponse = null;

            RestliCallback <EntityResponse <Greeting> > .SuccessHandler successHandler = delegate(EntityResponse <Greeting> response)
            {
                greeting = response.element;
                blocker.Set();
            };
            RestliCallback <EntityResponse <Greeting> > .ErrorHandler errorHandler = delegate(ClientErrorResponse response)
            {
                errorResponse = response;
                blocker.Set();
            };
            RestliCallback <EntityResponse <Greeting> > callback = new RestliCallback <EntityResponse <Greeting> >(successHandler, errorHandler);

            client.RestRequestAsync(request, callback);

            blocker.WaitOne();

            Assert.IsNull(greeting);
            Assert.IsNotNull(errorResponse);
            Assert.AreEqual(400, errorResponse.status);

            RestliException error = errorResponse.error;

            Assert.IsNotNull(error);
            Assert.IsNotNull(error.Message);
            Assert.IsNull(error.InnerException);

            ErrorResponse details = error.details;

            Assert.IsNotNull(details);
            Assert.AreEqual(400, details.status);
            Assert.AreEqual("Negative key.", details.message);
            Assert.AreEqual("com.linkedin.restli.server.RestLiServiceException", details.exceptionClass);
            Assert.IsTrue(details.hasStackTrace);
        }
Exemplo n.º 4
0
        public TransportResponse(HttpResponse response)
        {
            int?httpStatus = null;

            // if response non-null, extract headers, status code, data, and error
            if (response != null)
            {
                headers    = response.headers;
                httpStatus = response.status;
                data       = DataUtil.BytesToMap(response.data);
                error      = response.error;
            }
            else
            {
                headers = new Dictionary <string, string>();
            }

            status = httpStatus;

            AddStatusOrHeaderError();
        }
Exemplo n.º 5
0
        public TransportResponse(Dictionary <string, object> data, HttpResponse response)
        {
            this.data = data;

            int?httpStatus = null;

            // if response non-null, extract headers, status code, and error
            if (response != null)
            {
                headers    = response.headers;
                httpStatus = response.status;
                error      = response.error;
            }
            else
            {
                headers = new Dictionary <string, string>();
            }

            status = httpStatus;

            AddStatusOrHeaderError();
        }
Exemplo n.º 6
0
        public void DecodeResponse()
        {
            ErrorResponseDecoder decoder = new ErrorResponseDecoder();

            Dictionary <string, object> data = new Dictionary <string, object>()
            {
                { "exceptionClass", "com.linkedin.restli.server.RestLiServiceException" },
                { "message", "Example message" },
                { "stackTrace", "Example stack trace" },
                { "status", 400 }
            };

            Dictionary <string, string> headers = new Dictionary <string, string>()
            {
                { RestConstants.kHeaderRestliErrorResponse, "true" }
            };

            RestliException   exception         = new RestliException("Server returned Rest.li error response", null);
            HttpResponse      httpResponse      = new HttpResponse(RestConstants.httpStatusInternalServerError, headers, null, exception);
            TransportResponse transportResponse = new TransportResponse(data, httpResponse);

            ClientErrorResponse response = decoder.DecodeResponse(transportResponse);

            ErrorResponse error = response.error.details;

            Assert.IsNotNull(error);

            Assert.IsTrue(error.hasExceptionClass);
            Assert.IsTrue(error.hasMessage);
            Assert.IsTrue(error.hasStackTrace);
            Assert.IsTrue(error.hasStatus);

            Assert.AreEqual("com.linkedin.restli.server.RestLiServiceException", error.exceptionClass);
            Assert.AreEqual("Example message", error.message);
            Assert.AreEqual("Example stack trace", error.stackTrace);
            Assert.AreEqual(400, error.status);
        }
Exemplo n.º 7
0
 public ClientErrorResponse(Dictionary <string, List <string> > headers, int status, RestliException error)
     : base(headers, status)
 {
     this.error = error;
 }