Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Koa send status 404 every time is

export async function getPlaces(ctx, next) {
    const { error, data } = await PlaceModel.getPlaces(ctx.query);
    console.log(error, data);
    if (error) {
        return ctx.throw(422, error);
    }
    ctx.body = data;
}

Koa everytime sends 404 status and empty body, what i'm doing wrong ?

like image 805
Shahen Hovhannisyan Avatar asked Dec 06 '25 06:12

Shahen Hovhannisyan


2 Answers

In seems that, await does not really "wait" and therefore returns too early (this results in a 404 error).

One reason for that could be that your PlaceModel.getPlaces(ctx.query) does not returns a promise. So it continues without waiting on results from getPlaces.

like image 148
Sebastian Hildebrandt Avatar answered Dec 07 '25 20:12

Sebastian Hildebrandt


I also had this issue, and resolved it by adding :

ctx.status = 200;

directly below

ctx.body = data;

like image 30
Kris Randall Avatar answered Dec 07 '25 22:12

Kris Randall



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!