[v4] support error handling flow like gRPC (#158)
Some checks failed
sync / sync (push) Failing after 1h5m56s
test / test (push) Failing after 1h9m11s
coverage / build (push) Failing after 1h9m22s

* add status package with tests and integrate into response parsing
* improve unit-tests
* improve readme
This commit is contained in:
2025-09-30 12:28:39 +05:00
committed by GitHub
parent 9bb2f8cffa
commit 6209a03044
7 changed files with 308 additions and 26 deletions

View File

@@ -139,6 +139,7 @@ err := c.Call(
```go
import (
http "go.unistack.org/micro-client-http/v4"
status "go.unistack.org/micro-client-http/v4/status"
jsoncodec "go.unistack.org/micro-codec-json/v4"
)
@@ -151,4 +152,13 @@ err := c.Call(
"403": &protoSpecialError{}, // <- key is the HTTP status code that is mapped to this error
}),
)
if err != nil {
s, ok := status.FromError(err)
if !ok {...}
code := s.Code() // HTTP status code
message := s.Message() // HTTP status text
details := s.Details() // Error type mapped from ErrorMap
}
```