I'm encountering an error while using Eventstore, specifically: Could not recognize BadRequest
;
The error message is originating from:
game process tick failed UnknownError: Could not recognize BadRequest
at unpackToCommandError (\node_modules\@eventstore\db-client\dist\streams\appendToStream\unpackError.js:53:12)
at ClientDuplexStreamImpl.<anonymous> (\node_modules\@eventstore\db-client\dist\streams\appendToStream\batchAppend.js:38:66)
It appears that the issue lies within my handler function:
async function gameProcessPush(channel,event) {
console.log("pushing:",event);
try {
console.log("trying to append..:",event);
await client.appendToStream("factory",[event]);
console.log("appending to stream");
} catch(e) {
console.log("game process tick failed",e);
throw {live: false, code: 26, event: event}
}
console.log("game processing...");
}
Can anyone help me identify what I might be doing incorrectly here?
Here's the remaining debug code:
processing factory failed {
live: false,
code: 26,
event: { type: 'factory-creation', sub: 'sub-factory', userid: 1 }
}
result in : undefined
Below is the full code snippet for reference:
import { streamNameFilter } from "@eventstore/db-client";
import { createSecureServer } from "http2";
import { runMain } from "module";
import { eventNames, mainModule } from "process";
import { arrayBuffer } from "stream/consumers";
import { SubscriptionInfo } from "./generated/persistent_pb";
import { AllStreamPosition } from "./generated/shared_pb";
const {EventStoreDBClient, FORWARDS, StreamNotFoundError, jsonEvent, START, END, excludeSystemEvents, eventTypeFilter} = require("@eventstore/db-client");
const client = new EventStoreDBClient({
endpoint: "localhost:2113",
}, {
insecure: true,
});
interface creationFactory {
userid: string,
location: [number,number,number],
name: string
type: string,
}
class Factory {
public async create(creation : creationFactory) {
console.log("creating new factory.....",creation);
const NewFactoryEvent = CreateEvent("factory-creation",{userid: 1, sub: "sub-factory"})
try {
console.log("creating newfac",NewFactoryEvent);
await gameProcessPush("factory",NewFactoryEvent)
} catch(error) {
console.log("processing factory failed",error);
}
}
}
function CreateEvent(type,data) {
return {type: type, sub: data.sub,
userid: data.userid,
}
}
async function gameProcessPush(channel,event) {
console.log("pushing:",event);
try {
console.log("trying to append..:",event);
await client.appendToStream("factory",[event]);
console.log("appending to stream");
} catch(e) {
console.log("game process tick failed",e);
throw {live: false, code: 26, event: event}
}
console.log("game processing...");
}
//new Factory().create({userid: "1", location: [1,1,1], name: "test bank", type: "BANK"});
async function test() {
try {
await new Factory().create({
userid: "1",
location: [0,0,0],
name: "test",
type: "factory",
});
} catch(e) {
console.log("factory creation faileD");
}
}
test().catch((e) => {console.log("test failed",e)}).then(function (data) {
console.log("result in : ",data);
});