feat: convert grpc errors to http status codes (#1997)
* feat: convert grpc errors to http status codes * chore: circuit break include unimplemented grpc error * chore: add reference link in comments
This commit is contained in:
@@ -8,6 +8,8 @@ import (
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/zeromicro/go-zero/core/logx"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
type message struct {
|
||||
@@ -95,6 +97,16 @@ func TestError(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestErrorWithGrpcError(t *testing.T) {
|
||||
w := tracedResponseWriter{
|
||||
headers: make(map[string][]string),
|
||||
}
|
||||
Error(&w, status.Error(codes.Unavailable, "foo"))
|
||||
assert.Equal(t, http.StatusServiceUnavailable, w.code)
|
||||
assert.True(t, w.hasBody)
|
||||
assert.True(t, strings.Contains(w.builder.String(), "foo"))
|
||||
}
|
||||
|
||||
func TestErrorWithHandler(t *testing.T) {
|
||||
w := tracedResponseWriter{
|
||||
headers: make(map[string][]string),
|
||||
|
||||
Reference in New Issue
Block a user