Giter Site home page Giter Site logo

关于 Error 的一些疑问 about kitex HOT 10 CLOSED

fan-x-ing avatar fan-x-ing commented on July 1, 2024
关于 Error 的一些疑问

from kitex.

Comments (10)

GuangmingLuo avatar GuangmingLuo commented on July 1, 2024

看下文档:https://www.cloudwego.io/zh/docs/kitex/tutorials/basic-feature/bizstatuserr/

from kitex.

fan-x-ing avatar fan-x-ing commented on July 1, 2024

看下文档:https://www.cloudwego.io/zh/docs/kitex/tutorials/basic-feature/bizstatuserr/

我看了这个地方https://www.cloudwego.io/zh/docs/kitex/tutorials/basic-feature/bizstatuserr/,我看提供了 NewBizStatusError 和 FromBizStatusError,但是我kitex端使用 NewBizStatusError 创造的 error,客户端不管怎么 if 都只是 nil,关于这个的用法相关,是否在 github 有案例?

from kitex.

GuangmingLuo avatar GuangmingLuo commented on July 1, 2024

可以收藏和clone下 Kitex-examples :https://github.com/cloudwego/kitex-examples/tree/main/business_exception

from kitex.

rogerogers avatar rogerogers commented on July 1, 2024

https://www.bilibili.com/video/BV1Nm41117Ri 视频中也有讲解,需要设置对应的 MetaHandler

from kitex.

fan-x-ing avatar fan-x-ing commented on July 1, 2024

https://www.bilibili.com/video/BV1Nm41117Ri 视频中也有讲解,需要设置对应的 MetaHandler

好的,感谢,我去学习一下!

from kitex.

fan-x-ing avatar fan-x-ing commented on July 1, 2024

可以收藏和clone下 Kitex-examples :https://github.com/cloudwego/kitex-examples/tree/main/business_exception

好的

from kitex.

GuangmingLuo avatar GuangmingLuo commented on July 1, 2024
image

from kitex.

fan-x-ing avatar fan-x-ing commented on July 1, 2024

好的,可能是少配置了 MetaHandler, 麻烦各位大佬了
我先去试试

from kitex.

fan-x-ing avatar fan-x-ing commented on July 1, 2024

我目前想要为我的自定义 Error 来实现 kerrors.BizStatusErrorIface 这个接口。我的代码这样实现的:

// Error 自定义错误
type Error struct {
	Msg string `json:"msg"`
	Err error  `json:"err"`
}

func NewError(msg string, err error) kerrors.BizStatusErrorIface {
	return &Error{Msg: msg, Err: err}
}

func (self *Error) BizStatusCode() int32 {
	return 0
}

func (self *Error) BizMessage() string {
	return self.Msg
}

func (self *Error) BizExtra() map[string]string {
	return map[string]string{
		"msg":   self.Msg,
		"error": self.Err.Error(),
	}
}

func (self *Error) Error() string {
	return self.Err.Error()
}

但是好像无法进行正常传输

from kitex.

jayantxie avatar jayantxie commented on July 1, 2024

业务异常状态码不能为0,否则无法识别为业务异常

from kitex.

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.