Java Code Examples for org.apache.servicecomb.swagger.invocation.exception.InvocationException#getErrorData()
The following examples show how to use
org.apache.servicecomb.swagger.invocation.exception.InvocationException#getErrorData() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RestProducerInvocationCreatorTest.java From servicecomb-java-chassis with Apache License 2.0 | 6 votes |
@Test public void should_failed_when_accept_is_not_support() { mockGetServicePathManager(); new Expectations() { { requestEx.getHeader(HttpHeaders.ACCEPT); result = "test-type"; restOperationMeta.ensureFindProduceProcessor(requestEx); result = null; } }; InvocationException throwable = (InvocationException) catchThrowable(() -> creator.create()); CommonExceptionData data = (CommonExceptionData) throwable.getErrorData(); assertThat(throwable.getStatusCode()).isEqualTo(NOT_ACCEPTABLE.getStatusCode()); assertThat(Json.encode(data)) .isEqualTo("{\"code\":\"SCB.00000000\",\"message\":\"Accept test-type is not supported\"}"); }
Example 2
Source File: ProducerOperationFilterTest.java From servicecomb-java-chassis with Apache License 2.0 | 6 votes |
@Test public void should_unify_IllegalArgumentException_message_when_convert_exception() throws NoSuchMethodException { setInvokeSyncMethod(); new Expectations() { { invocation.toProducerArguments(); result = new Object[] {1}; } }; CompletableFuture<Response> future = filter.onFilter(invocation, FilterNode.EMPTY); assertThat(future).hasFailedWithThrowableThat() .isInstanceOf(IllegalArgumentException.class) .hasMessage("wrong number of arguments"); InvocationException throwable = Exceptions .convert(invocation, catchThrowable(() -> future.get()), INTERNAL_SERVER_ERROR); assertThat(throwable).hasCauseInstanceOf(IllegalArgumentException.class); CommonExceptionData data = (CommonExceptionData) throwable.getErrorData(); assertThat(data.getMessage()).isEqualTo("Parameters not valid or types not match."); }
Example 3
Source File: AbstractEdgeDispatcher.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
protected void onFailure(RoutingContext context) { LOGGER.error("edge server failed.", context.failure()); HttpServerResponse response = context.response(); if (response.closed() || response.ended()) { return; } if (context.failure() instanceof InvocationException) { InvocationException exception = (InvocationException) context.failure(); response.setStatusCode(exception.getStatusCode()); response.setStatusMessage(exception.getReasonPhrase()); if (null == exception.getErrorData()) { response.end(); return; } String responseBody; try { responseBody = RestObjectMapperFactory.getRestObjectMapper().writeValueAsString(exception.getErrorData()); response.putHeader("Content-Type", MediaType.APPLICATION_JSON); } catch (JsonProcessingException e) { responseBody = exception.getErrorData().toString(); response.putHeader("Content-Type", MediaType.TEXT_PLAIN); } response.end(responseBody); } else { response.setStatusCode(Status.BAD_GATEWAY.getStatusCode()); response.setStatusMessage(Status.BAD_GATEWAY.getReasonPhrase()); response.end(); } }
Example 4
Source File: RestProducerInvocationCreatorTest.java From servicecomb-java-chassis with Apache License 2.0 | 5 votes |
@Test public void should_failed_when_not_defined_any_schema() { mockGetServicePathManager(null); InvocationException throwable = (InvocationException) catchThrowable(() -> creator.create()); CommonExceptionData data = (CommonExceptionData) throwable.getErrorData(); assertThat(throwable.getStatusCode()).isEqualTo(NOT_FOUND.getStatusCode()); assertThat(Json.encode(data)).isEqualTo("{\"code\":\"SCB.00000002\",\"message\":\"Not Found\"}"); }
Example 5
Source File: ParameterValidatorFilterTest.java From servicecomb-java-chassis with Apache License 2.0 | 4 votes |
private CommonExceptionData getExceptionData() { InvocationException invocationException = getException(); return (CommonExceptionData) invocationException.getErrorData(); }