Skip to content
This repository was archived by the owner on Aug 31, 2024. It is now read-only.
This repository was archived by the owner on Aug 31, 2024. It is now read-only.

convert.back() not respecting return from function? #10

@andrewc89

Description

@andrewc89

I am working on a Koa v1 app and would like to implement new routes with async/await instead of generator functions. I found this library has convert.back() which is mostly working for me. However, the following example code will illustrate my problem:

router.get('/endpoint',
async function(next) {
    const token = this.request.headers.token;
    if (!token) {
        this.response.status = 401;
        return;
    }
    // I assume next is a Promise so this is not an issue?
    await next;
},
async function(next) {
    // This code still executes, even if there is no token defined on the headers.

    // Do something important that shouldn't execute with invalid auth...
});

return convert.back(router.routes());

If there is no token defined, the endpoint does return a 401 and exits the first function, but the second function is still executed. If I set up the first function as a generator function and use yield next, it works as would be expected.

Versions:

node: 6.13.1
npm: 3.10.10

├─┬ koa@1.6.0
│ ├── koa-compose@2.5.1
│ ├── koa-is-json@1.0.0
├─┬ koa-convert@1.2.0
│ └── koa-compose@3.2.1
├── koa-json-logger@1.0.2
├─┬ koa-router@5.4.2
├─┬ koa-socket@4.4.0
│ ├── koa-compose@3.1.0
├─┬ koa-static-server@0.1.8
│ └─┬ koa-send@1.3.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions