try to fix this spaghetti of a code
This commit is contained in:
+2
-2
@@ -1,6 +1,6 @@
|
||||
const crypto = require('node:crypto');
|
||||
const {EventEmitter} = require('node:events');
|
||||
const {KeyedQueue, AppError, hash} = require('./core');
|
||||
const {KeyedQueue, AppError, hash, canonical} = require('./core');
|
||||
const engine = require('./engine');
|
||||
|
||||
function createLobbyService(repository, config) {
|
||||
@@ -38,7 +38,7 @@ function createLobbyService(repository, config) {
|
||||
return queue.run([...(membershipMutation ? ['membership'] : []), ...(username ? [`account:${username}`] : []),
|
||||
...(message.lobbyId ? [`lobby:${message.lobbyId}`] : [])], async () => {
|
||||
const id = `${username || 'system'}:${message.requestId}`;
|
||||
const fingerprint = hash(JSON.stringify(message));
|
||||
const fingerprint = hash(JSON.stringify(canonical(message)));
|
||||
const prior = await repository.command(id);
|
||||
if (prior) {
|
||||
if (prior.fingerprint !== fingerprint) throw new AppError('IDEMPOTENCY_CONFLICT', 'Request ID was reused', 409);
|
||||
|
||||
Reference in New Issue
Block a user