You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@servicecomb.apache.org by GitBox <gi...@apache.org> on 2018/05/09 03:22:16 UTC

[GitHub] zhang4045 opened a new issue #694: 统一异常处理

zhang4045 opened a new issue #694: 统一异常处理
URL: https://github.com/apache/incubator-servicecomb-java-chassis/issues/694
 
 
   自定义覆盖SwaggerProducerOperation类,在接口中抛出自定义异常,在doInvoke()方法中,捕获异常处理
   ServiceRuntimeException为自定义异常,debug模式下,v2是ServiceRuntimeException,但是v2 instanceof ServiceRuntimeException判断通过不了。
   代码如下:
   ```
   public Response doInvoke(SwaggerInvocation invocation) {
           Response response = null;
           try {
               Object[] args = this.argumentsMapper.toProducerArgs(invocation);
               Object result = this.producerMethod.invoke(this.producerInstance, args);
               response = this.responseMapper.mapResponse(invocation.getStatus(), result);
           } catch (InvocationTargetException var5) {
               Throwable v2 = var5.getTargetException();
               Throwable v3 = var5.getTargetException().getCause();
               Class aClass = v2.getClass();
               Class serviceRuntimeExceptionClass = ServiceRuntimeException.class;
               if(v2 instanceof ServiceRuntimeException){
                   ServiceRuntimeException v1 = (ServiceRuntimeException)v2;
                   BackVO backVO = new BackVO();
                   backVO.setStatus(v1.getErrCode());
                   backVO.setMessage(v1.getMessage());
                   response = this.responseMapper.mapResponse(invocation.getStatus(), backVO);
               }else{
                   response = this.processException(invocation, var5);
               }
           } catch (Throwable var5) {
               response = this.processException(invocation, var5);
           }
   
           return response;
       }
   ```
   ![2 q pp1v7 ksddx 1 t](https://user-images.githubusercontent.com/13702363/39794058-f1ae0e44-537a-11e8-9c6d-37304cb3eac5.png)

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services