[v4] support error handling flow like gRPC (#158)
* add status package with tests and integrate into response parsing * improve unit-tests * improve readme
This commit is contained in:
10
README.md
10
README.md
@@ -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
|
||||
}
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user