go – How can I send the error body from grpc-gateway?

We are using grpc-gateway in our service. In the service, we are calling an API and will get some error code from an API for non-2XX responses. We have to wrap that error and return it from the service.

I am using grpc status to return that from the service.


func wrapError(err error, statusCode codes.Code, errorCode string) error {
    errorInfo := &dealv1.ErrorResponse{
        ErrorCode: &errorCode,
    status, err := status.New(statusCode, err.Error()).WithDetails(errorInfo)
    if err != nil {
        return err
    return status.Err()

I am using a custom error body inside details to keep future extensibility in mind.


  "code": 2,
  "message": "",
  "details": [
      "@type": "",
      "errorCode": "overlaping_error_code"

I am getting this @type property also with protobuf path as value. Does someone know how can I get rid of this @type property or is there any better way to return the error body?

Read more here: Source link