Giter VIP home page Giter VIP logo

Comments (3)

0000005 avatar 0000005 commented on August 21, 2024

推荐解决方案
自己继承RuntimeException 实现一个ServiceException。

public class ServiceException extends RuntimeException {
    private Object data;

    public ServiceException(String message) {
        super(message);
    }

    public ServiceException(String message, Object data) {
        super(message);
        this.data = data;
    }

    public ServiceException(String message, Throwable cause) {
        super(message, cause);
    }

    public Object getData() {
        return this.data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}

然后实现WebMvcConfigurer 进行统一异常处理。
具体可以参考这篇博文
https://www.cnblogs.com/gdwkong/p/8969963.html

正确的写法是

try
{
   //do something
}
catch(Exception e)
{
    //do something handle the exception
    log.error("do something error",e);
    //返回到前端的内容会根据你实现的WebMvcConfigurer 类封装成你想要的形式
    throw new ServiceException("UPLOAD ERROR");
}

from kiftd-source.

KOHGYLW avatar KOHGYLW commented on August 21, 2024

kiftd的源代码中确实还存在很多设计缺陷,您提到的异常处理就是其中一类。当初很多异常都是只考虑了它对前端用户产生的影响,因此只做了基本的逻辑反馈。您给出的建议已经阅读,在后续优化代码(如果有时间的话)时会作为参考,不过,一般而言这一过程可能需要很长的时间了。
再次感谢您的反馈,这是kiftd不断进步的最佳动力。

from kiftd-source.

dandycheung avatar dandycheung commented on August 21, 2024

@81519434 @KOHGYLW 建议两位可以达成一个共识,就是 @81519434 可以 fork 一份进行相应的改进,完成后 PR 到 @KOHGYLW ,而主干在开发过程中尽量保持不再引入类似的使用。

from kiftd-source.

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.