Friday, 17 June 2022

Eventstore UnknownError: Could not recognize BadRequest

I'm currently using Eventstore, and I'm receiving the following error: Could not recognize BadRequest;

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)

For some reason, it seems like it is something with my handler:

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...");

}

What am I doing wrong here?

rest of debug code:

processing factory failed {
  live: false,
  code: 26,
  event: { type: 'factory-creation', sub: 'sub-factory', userid: 1 }
}
result in :  undefined

Full code:

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);
});


from Eventstore UnknownError: Could not recognize BadRequest

No comments:

Post a Comment