accountUpdateId() → Throws: Error whilst making RPC call: SyntaxError: Unexpected end of JSON input
TL;TR
Running an RPC call from the Nakama Console results in:
Error whilst making RPC call: SyntaxError: Unexpected end of JSON input
Current setup:
- Versions: Nakama 3.22.0 running in a Docker container (macOS)
- Server Framework Runtime language: TS/JS
rpcUpdateLastOnline()
In the minimal code example of index.js
below, you find the rpcUpdateLastOnline()
function.
This function behavior should be: setting the current users metadata
field: lastOnline
with the current date stamp when he/she goes offline.
The function is a modification of the example mentioned here: heroiclabs.com/reference/#accountUpdateId
"use strict";
function InitModule(ctx, logger, nk, initializer) {
initializer.registerRpc('healthcheck', rpcHealthCheck);
initializer.registerRpc('updateLastOnline', rpcUpdateLastOnline);
logger.info('Javascript InitModule loaded');
}
function rpcHealthCheck(ctx, logger, nk, payload) {
logger.info('HealthCheck RPC called');
return JSON.stringify({ success: true });
}
// RPC function to update last_online metadata for the current user
function rpcUpdateLastOnline(ctx, logger, nk, payload) {
if (!ctx.userId) {
throw Error('No user ID in context');
}
if (payload) {
throw Error('no input allowed');
}
var userId = ctx.userId;
var username = null;
var now = new Date().toISOString();
var metadata = { lastOnline: now };
var displayName = null;
var timezone = null;
var location = null;
var langTag = null;
var avatarUrl = null;
try {
nk.accountUpdateId(userId, username, displayName, timezone, location, langTag, avatarUrl, metadata);
}
catch (error) {
logger.error('updateLastOnline error: %q', error);
throw error;
}
};
The Issue:
Running the RPC call from the Nakama Console results in:
Error whilst making RPC call: SyntaxError: Unexpected end of JSON input
When I chance the code to
only
update the displayName
I also get the same error
as mentioned above:
var userId = ctx.userId;
var username = null;
var metadata = null;
var displayName = "MyName";
var timezone = null;
var location = null;
var langTag = null;
var avatarUrl = null;
try {
nk.accountUpdateId(userId, username, displayName, timezone, location, langTag, avatarUrl, metadata);
BUT when all arguments (other than userId) are
null
like below…
var userId = ctx.userId;
var username = null;
var metadata = null;
var displayName = null;
var timezone = null;
var location = null;
var langTag = null;
var avatarUrl = null;
try {
nk.accountUpdateId(userId, username, displayName, timezone, location, langTag, avatarUrl, metadata);
I get an expected reponse:
"rpc error: code = Internal desc = GoError: error trying to update user:
No fields to update. at github.com/heroiclabs/nakama/v3/server
.(*runtimeJavascriptNakamaModule).mappings.
(*runtimeJavascriptNakamaModule).accountUpdateId.func40 (native)"
???
Somehow - I think - the generated JSON string does not get constructed/parsed the right way. And I am scratching my head for hours to tackle this.
What am I missing?