Search in sources :

Example 66 with ErrorResponse

use of com.linkedin.restli.common.ErrorResponse in project rest.li by linkedin.

the class TestErrorResponseBuilder method testNullStatus.

@Test
public void testNullStatus() {
    RestLiServiceException exception = new RestLiServiceException((HttpStatus) null);
    ErrorResponseBuilder builder = new ErrorResponseBuilder(ErrorResponseFormat.FULL);
    ErrorResponse errorResponse = builder.buildErrorResponse(exception);
    Assert.assertFalse(errorResponse.hasStatus());
}
Also used : RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) ErrorResponse(com.linkedin.restli.common.ErrorResponse) Test(org.testng.annotations.Test)

Example 67 with ErrorResponse

use of com.linkedin.restli.common.ErrorResponse in project rest.li by linkedin.

the class TestErrorResponseBuilder method testErrorDetailsFromDataMap.

@Test
public void testErrorDetailsFromDataMap() {
    RestLiServiceException exception = new RestLiServiceException(HttpStatus.S_200_OK, "Some message", new IllegalStateException("Some other message"));
    exception.setCode("INVALID_SOMETHING");
    exception.setDocUrl("www.documentation.com");
    exception.setRequestId("id123");
    exception.setErrorDetails((DataMap) null);
    Assert.assertFalse(exception.hasErrorDetails());
    ErrorResponseBuilder builder = new ErrorResponseBuilder(ErrorResponseFormat.FULL);
    ErrorResponse errorResponse = builder.buildErrorResponse(exception);
    Assert.assertFalse(errorResponse.hasErrorDetails());
    Assert.assertTrue(errorResponse.hasExceptionClass());
    Assert.assertTrue(errorResponse.hasStatus());
    Assert.assertTrue(errorResponse.hasMessage());
    Assert.assertTrue(errorResponse.hasCode());
    Assert.assertTrue(errorResponse.hasStackTrace());
    Assert.assertTrue(errorResponse.hasDocUrl());
    Assert.assertTrue(errorResponse.hasRequestId());
    exception.setOverridingFormat(ErrorResponseFormat.MESSAGE_AND_SERVICECODE);
    errorResponse = builder.buildErrorResponse(exception);
    Assert.assertFalse(errorResponse.hasErrorDetails());
    Assert.assertFalse(errorResponse.hasExceptionClass());
    Assert.assertTrue(errorResponse.hasStatus());
    Assert.assertTrue(errorResponse.hasMessage());
    Assert.assertTrue(errorResponse.hasCode());
    Assert.assertFalse(errorResponse.hasStackTrace());
    Assert.assertFalse(errorResponse.hasDocUrl());
    Assert.assertFalse(errorResponse.hasRequestId());
}
Also used : RestLiServiceException(com.linkedin.restli.server.RestLiServiceException) ErrorResponse(com.linkedin.restli.common.ErrorResponse) Test(org.testng.annotations.Test)

Aggregations

ErrorResponse (com.linkedin.restli.common.ErrorResponse)67 Test (org.testng.annotations.Test)35 DataMap (com.linkedin.data.DataMap)19 HashMap (java.util.HashMap)15 Greeting (com.linkedin.restli.examples.greetings.api.Greeting)14 RestResponse (com.linkedin.r2.message.rest.RestResponse)9 RestRequest (com.linkedin.r2.message.rest.RestRequest)8 EntityResponse (com.linkedin.restli.common.EntityResponse)8 ResponseImpl (com.linkedin.restli.internal.client.ResponseImpl)8 RestLiServiceException (com.linkedin.restli.server.RestLiServiceException)8 RestException (com.linkedin.r2.message.rest.RestException)7 TestRecord (com.linkedin.restli.client.test.TestRecord)7 Callback (com.linkedin.common.callback.Callback)6 BatchKVResponse (com.linkedin.restli.client.response.BatchKVResponse)6 BatchResponse (com.linkedin.restli.common.BatchResponse)6 EmptyRecord (com.linkedin.restli.common.EmptyRecord)6 IOException (java.io.IOException)6 RequestContext (com.linkedin.r2.message.RequestContext)5 BatchCollectionResponse (com.linkedin.restli.common.BatchCollectionResponse)5 BatchFinderCriteriaResult (com.linkedin.restli.common.BatchFinderCriteriaResult)5