Giter Club home page Giter Club logo

Comments (2)

iohao avatar iohao commented on August 16, 2024

默认情况下,框架是不会携带异常信息的,原因上面已经提过了。

但我们可以通过扩展的方式来实现,将异常信息携带到请求端,如下:

框架在 ActionMethodResultWrap 时,已经把异常信息存放到 flowContext.option(FlowAttr.msgException, msgException.getMessage()) 中了。

之后我们重写一个 ActionAfter 类,并配置到业务框架中,把默认的实现 DefaultActionAfter 替换就可以了。

重写的 ActionAfter 实现类中,将这个异常信息在发送之前保存到 response 中就可以。

public final class MyActionAfter implements ActionAfter {
    ... ... 省略部分代码

    @Override
    public void execute(final FlowContext flowContext) {
        ... ... 省略部分代码

        // 有错误就响应给调用方
        if (response.hasError()) {
            // 异常消息发送到请求端
            String msg = flowContext.option(FlowAttr.msgException);
            response.setValidatorMsg(msg);

            asyncCtx.sendResponse(response);
            return;
        }

        ... ... 省略部分代码
    }
}

from iogame.

iohao avatar iohao commented on August 16, 2024

see https://www.yuque.com/iohao/game/avlo99#G4cvL

from iogame.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.