diff --git a/runtime/handler.go b/runtime/handler.go index 577a060f74d..3725a56fd41 100644 --- a/runtime/handler.go +++ b/runtime/handler.go @@ -9,11 +9,19 @@ import ( "github.com/golang/glog" "github.com/golang/protobuf/proto" "golang.org/x/net/context" + "google.golang.org/grpc" ) type responseStreamChunk struct { - Result proto.Message `json:"result,omitempty"` - Error string `json:"error,omitempty"` + Result proto.Message `json:"result,omitempty"` + Error responseStreamError `json:"error,omitempty"` +} + +type responseStreamError struct { + GrpcCode int `json:"grcp_code, omitempty"` + HTTPCode int `json:"http_code, omitempty"` + Message string `json:"message, omitempty"` + HTTPStatus string `json:"http_status, omitempty"` } // ForwardResponseStream forwards the stream from gRPC server to REST client. @@ -35,7 +43,13 @@ func ForwardResponseStream(ctx context.Context, w http.ResponseWriter, req *http return } if err != nil { - buf, merr := json.Marshal(responseStreamChunk{Error: err.Error()}) + grpcCode := grpc.Code(err) + httpCode := HTTPStatusFromCode(grpcCode) + resp := responseStreamChunk{Error: responseStreamError{GrpcCode: int(grpcCode), + HTTPCode: httpCode, + Message: err.Error(), + HTTPStatus: http.StatusText(httpCode)}} + buf, merr := json.Marshal(resp) if merr != nil { glog.Errorf("Failed to marshal an error: %v", merr) return