I’m trying to add a hook to prevent given usernames to be used, registered on
UpdateAccount function. According to Server doc we need to return
nil to halt the process. By doing this, the client sees the error code as
"NotFound" and message
"The resource could not be found". I guess because putting
nil prevent the UpdateAccount function to find the user and trigger this, but on the client we can’t have an error code to explicitely know if was our hook that halted the process. The client error code is an enum so I guess we could not add new values.
Then I thought that instead of returning
nil I raise an error doing
error("Username forbidden") and then the client receive
"InternalError" as error code and
"Username forbidden" as message. That way I could know with the message that it’s my code which triggered the error.
Is this a good solution? Althought it’s not what the doc tells to do.
Hello @AlexandreK38, could you please share what runtime you are using is and what your hook code looks like?
I’m running Nakama 3.6 locally and client is latest Nakama Cocos2d-x C++ client (2.5.1)
Here is the Lua code
local function filter_username(context, json)
if json.username == "toto" then
-- return nil
Please take a look at Custom rpc response status in lua - #2 by zyro, it should cover what you’re looking for.
Thanks for the answer,
But as Zyro said in his post, the error code is restricted to a given list
Where the code must be a GRPC response code numeric value from this list
So you can’t give your own error code, the only way to know it’s your error is the error message I guess.
Those gRPC codes map to HTTP status codes as listed here: googleapis/code.proto at master · googleapis/googleapis · GitHub. I’d suggest you use code 3, which maps to an http 400 status.
Yes that seems to be better than the InternalError (500) if no code is given, thanks