Git Product home page Git Product logo

kratos-mono-repo's People

Contributors

wjs1152283574 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

kratos-mono-repo's Issues

关于自定义error的疑问,望大佬解答

项目里自定义error有两种方式

  1. pb里定义
api/shop/service/v1/shop_error.proto
enum ShopServiceErrorReason {
    option (errors.default_code) = 500;

    SHOP_RECORD_NOT_FOUND = 0 [(errors.code) = 404];
    SHOP_CONTENT_MISSING = 1 [(errors.code) = 400];
    SHOP_DUPLICATE_ENTRY = 2 [(errors.code) = 400];
    SHOP_PERMITION_DENIED = 3 [(errors.code) = 401];
    SHOP_INVALID_TOKEN = 4 [(errors.code) = 401];
}
  • 这里的reason枚举可以提供给前端做判断
  1. go代码里定义
pkg/errors/shop.go
RecordNotFound = errors.New(404, "RecordNotFound", "Record Not Found")
  • 这里的reason是字符串,我理解是服务内部使用,不清楚是不是这个意思
  • 为什么第二种方式定义的error返回给前端了?这种前端不好判断啊

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.