Skip to content

Commit

Permalink
Improve handling of grpc errors
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksej-paschenko committed Aug 15, 2024
1 parent 0276130 commit 887bb5b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ require (
golang.org/x/exp v0.0.0-20230725093048-515e97ebf090
golang.org/x/net v0.23.0
golang.org/x/text v0.14.0
google.golang.org/grpc v1.31.0
gopkg.in/yaml.v3 v3.0.1
)

Expand Down Expand Up @@ -66,6 +67,7 @@ require (
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/tools v0.19.0 // indirect
google.golang.org/genproto v0.0.0-20200825200019-8632dd797987 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEY
google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7FcilCzHH/e9qn6dsT145K34l5v+OpcnNgKAAA=
google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20200825200019-8632dd797987 h1:PDIOdWxZ8eRizhKa1AAvY53xsvLB1cWorMjslvY3VA8=
google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
Expand All @@ -569,6 +570,7 @@ google.golang.org/grpc v1.27.1/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8
google.golang.org/grpc v1.28.0/go.mod h1:rpkK4SK4GF4Ach/+MFLZUBavHOvF2JJB5uozKKal+60=
google.golang.org/grpc v1.29.1/go.mod h1:itym6AZVZYACWQqET3MqgPpjcuV5QH3BxFS3IjizoKk=
google.golang.org/grpc v1.30.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
google.golang.org/grpc v1.31.0 h1:T7P4R73V3SSDPhH7WW7ATbfViLtmamH0DKrP3f9AuDI=
google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
Expand Down
18 changes: 11 additions & 7 deletions pkg/api/converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,26 @@ import (
"strings"
"unicode"

"github.com/tonkeeper/opentonapi/pkg/core"
imgGenerator "github.com/tonkeeper/opentonapi/pkg/image"
walletPkg "github.com/tonkeeper/opentonapi/pkg/wallet"
"github.com/go-faster/jx"
"github.com/tonkeeper/tongo"
"github.com/tonkeeper/tongo/boc"
"github.com/tonkeeper/tongo/tlb"
"google.golang.org/grpc/status"

"github.com/go-faster/jx"
"github.com/tonkeeper/opentonapi/pkg/core"
imgGenerator "github.com/tonkeeper/opentonapi/pkg/image"
"github.com/tonkeeper/opentonapi/pkg/oas"
"github.com/tonkeeper/tongo"
walletPkg "github.com/tonkeeper/opentonapi/pkg/wallet"
)

func toError(code int, err error) *oas.ErrorStatusCode {
msg := err.Error()
if strings.HasPrefix(err.Error(), "failed to connect to") || strings.Contains(err.Error(), "host=") {
msg = "unknown error"
return &oas.ErrorStatusCode{StatusCode: code, Response: oas.Error{Error: "unknown error"}}
}
if s, ok := status.FromError(err); ok {
return &oas.ErrorStatusCode{StatusCode: code, Response: oas.Error{Error: s.Message()}}
}
msg := err.Error()
return &oas.ErrorStatusCode{StatusCode: code, Response: oas.Error{Error: msg}}
}

Expand Down

0 comments on commit 887bb5b

Please sign in to comment.