diff --git a/lua/presence/discord.lua b/lua/presence/discord.lua index e6b97f4..83fd77a 100644 --- a/lua/presence/discord.lua +++ b/lua/presence/discord.lua @@ -54,7 +54,12 @@ end -- Make a remote procedure call to Discord -- Callback argument in format: on_response(error[, response_table]) function Discord:call(opcode, payload, on_response) - self.encode_json(payload, function(body) + self.encode_json(payload, function(success, body) + if not success then + self.log:warn(string.format("Failed to encode payload: %s", vim.inspect(body))) + return + end + -- Start reading for the response self.pipe:read_start(function(...) self:read_message(payload.nonce, on_response, ...) @@ -86,11 +91,11 @@ function Discord:read_message(nonce, on_response, err, chunk) on_response(err_message) elseif chunk then - local header_size = 9 - local message = chunk:sub(header_size) + -- Strip header from the chunk + local message = chunk:match("({.+)") local response_opcode = struct.unpack("