Error Handling in nakama/lua

I am using some hooks for data validation in nakama. In order to return correct status codes, it seems using error({msg, code}) function is the only way which works fine.
My problem is that every time that I call this function, even for 0 (200) and 3 (400) status codes, the logger (level=error) logs it as an error. Is there a way to prevent this, because we don’t want these situations to be logged. and if not, is there any other way to return a response with a status code other than 200?

I’ve had a look at the code, looks like right now any Lua function that calls error(...) will trigger a log message.

I think it would make sense for the server to observe calls to error({msg, code}) as “expected” errors and not log anything, as that format could only come from explicit calls from the Lua runtime which we can assume the developer has handled appropriately already. We’ll make this change for the next release. :+1:

Side note: does passing code 0 (which maps to HTTP 200 OK) work as you expect from a client perspective? Do you get the appropriate response code and body in the client response?


Thank you. Is there any estimation on the time the next release will be available?

About your question: yes, code 0 maps to 200 OK status code and works fine. But we’re using an older version of nakama right now. I’ve checked the code and it seems that passing code 0 is not valid anymore (which makes sense).

Is there any estimation on the time the next release will be available?

The current timeline is to do the next server release before the end of this month.

1 Like

This commit addresses the issue, and will be part of the next release - look out for Nakama 2.15.0.


The latest server release with the change for how these programmatic errors which are intentionally returned by the server logic is now done.