Getting Internal server error instead of response status and body

466 views Asked by At

I am trying to build my first API with deno and mongoDB. I have managed to make it work, to recieve the request and send the data from request in response to mongoDb.

But I am struggling with getting the response status and body. I always get Internal server error. These two response are always skipped. I have found out when I delete the mongoDB insertOne method. I am getting the response as I should.

createTodo: async (
    {request, response}: { request: any; response: any },
) => {
    const createdTodo = await request.body();
    const values = await createdTodo.value;
    console.log(values)
    if (!request.hasBody) {
        response.status = 400;
        response.body = {
            success: false,
            message: "No data provided",
        };
        return;
    }

    let newTodo = {
        id: v4.generate(),
        todo: values.todo,
        isCompleted: false,
    };
    await TodoDB.insertOne({ //<--- when deleted, it starts working but without status and body
        newTodo
    });
     response.status = 200;
     response.body = {
        success: true,
        newTodo,
    };
},
1

There are 1 answers

0
Lumca On

Solved it by writing the code to try and catch block and figured out I have written URI majorit instead of majority.