public ErrorResponse buildErrorResponse(RestLiServiceException result)
  {
    // In some cases, people use 3XX to signal client a redirection. This falls into the category of blurred boundary
    // whether this should be an error or not, in order to not disrupt change the behavior of existing code
    // Thus excluding logging errors for 3XX
    if (result.getStatus() != null && result.getStatus().getCode() < HttpStatus.S_300_MULTIPLE_CHOICES.getCode())
    {
      // Invalid to send an error response with success status codes. This should be converted to 500 errors.
      // Logging an error message now to detect and fix current use cases before we start converting to 500.
      LOGGER.error("Incorrect use of success status code with error response", result);
    }

    if (result.getStatus() == HttpStatus.S_204_NO_CONTENT)
    {
      // HTTP Spec requires the response body to be empty for HTTP status 204.
      return new ErrorResponse();
    }

    return buildErrorResponse(result, result.hasOverridingErrorResponseFormat() ? result.getOverridingFormat() : _errorResponseFormat);
  }
@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());
  }