Ai
11 Star 11 Fork 0

Gitee 极速下载/goa

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/goadesign/goa
克隆/下载
grpc_error.go 1.79 KB
一键复制 编辑 原始数据 按行查看 历史
Nitin Mohan 提交于 2020-07-18 04:27 +08:00 . Support GRPC error responses in API (#2616)
package expr
import (
"goa.design/goa/eval"
)
type (
// GRPCErrorExpr defines a gRPC error response including its name,
// status, and result type.
GRPCErrorExpr struct {
// ErrorExpr is the underlying goa design error expression.
*ErrorExpr
// Name of error to match it up with the appropriate ErrorExpr.
Name string
// Response is the corresponding gRPC response.
Response *GRPCResponseExpr
}
)
// EvalName returns the generic definition name used in error messages.
func (e *GRPCErrorExpr) EvalName() string {
return "gRPC error " + e.Name
}
// Validate makes sure there is a error expression that matches the gRPC error
// expression.
func (e *GRPCErrorExpr) Validate() *eval.ValidationErrors {
verr := new(eval.ValidationErrors)
switch p := e.Response.Parent.(type) {
case *GRPCEndpointExpr:
if p.MethodExpr.Error(e.Name) == nil {
verr.Add(e, "Error %#v does not match an error defined in the method", e.Name)
}
case *GRPCServiceExpr:
if p.Error(e.Name) == nil {
verr.Add(e, "Error %#v does not match an error defined in the service", e.Name)
}
case *RootExpr:
if Root.Error(e.Name) == nil {
verr.Add(e, "Error %#v does not match an error defined in the API", e.Name)
}
}
return verr
}
// Finalize looks up the corresponding method error expression.
func (e *GRPCErrorExpr) Finalize(a *GRPCEndpointExpr) {
var ee *ErrorExpr
switch p := e.Response.Parent.(type) {
case *GRPCEndpointExpr:
ee = p.MethodExpr.Error(e.Name)
case *GRPCServiceExpr:
ee = p.Error(e.Name)
case *GRPCExpr:
ee = Root.Error(e.Name)
}
e.ErrorExpr = ee
e.Response.Finalize(a, e.AttributeExpr)
}
// Dup creates a copy of the error expression.
func (e *GRPCErrorExpr) Dup() *GRPCErrorExpr {
return &GRPCErrorExpr{
ErrorExpr: e.ErrorExpr,
Name: e.Name,
Response: e.Response.Dup(),
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/goa.git
git@gitee.com:mirrors/goa.git
mirrors
goa
goa
v2.2.5

搜索帮助