0

I also want to send an error code other than the error message to client applications using the shim.Error function,but it only accepts a msg parameter, how to do that?

xuxu
  • 6,374
  • 1
  • 17
  • 11

1 Answers1

1

shim.Error returns a response struct.

func Error(msg string) pb.Response {
    return pb.Response{
        Status:  ERROR,
        Message: msg,
    }
}

Status is set to ERROR const, which is defined as 500. But you can use any error code you want that is >= 400.

So instead of using Error function you construct the response yourself and set the status code.

return pb.Response{
        Status:  404,
        Message: "Invoke method you wanted to trigger does not exist",
    } 

Or you can compose your own Error function which also accepts a status code, and makes sure that is in the error range.

Last option is to use the Payload property of the response, and add details of the error including the status code in the payload.

hazimdikenli
  • 5,709
  • 8
  • 37
  • 67