Custom rpc response status in lua

I want to response different status codes for different payloads that comes to my custom rpc. Now if I return payload the status will be 200 and if I use error() the status will be 500. I want custom status codes (e.g. 400, 401…) And 500 is server internal error and it’s not clear as it should be for some conditions.

The Lua runtime can inspect values you pass to the error function and determine if it can extract a message and response code. You can do this:

local message = "my error message"
local code = 13
error({message, code})

Where the code must be a GRPC response code numeric value from this list and will be mapped to a HTTP response code if necessary using this translation.