Best Practice for Returning Error from Before Hook?

The stacktrace is now an option: Server Configuration - Heroic Labs Documentation, which should default to false.

I’ve just tried the following example on latest Nakama (v3.31.0):

local function before_hook(context, payload)
  return error({ "guild name is in use", 6 })
end
nk.register_req_before(before_hook, "AuthenticateCustom")

And this is what I got back from the API call:

{
    "code": 6,
    "message": "guild name is in use"
}

So I’m not sure what you mean with:

The actual error code is 0. (…)

Can you give a sample of how you’re handling the request and response in C++?