node.jskoakoa-routerkoa2

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 ?


Solution

  • 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.