koajs / router

Router middleware for Koa. Maintained by @forwardemail and @ladjs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not Implemented and Not Allowed error response docs example w/ Hapi Boom doesn't work

RavenHursT opened this issue · comments

node.js version:

❯ node -v
v14.17.3

npm/yarn and version:

❯ npm -v
6.14.13

@koa/router version: 10.1.0

koa version: 2.13.1

Code sample:

Borrowed from https://github.com/koajs/router/blob/master/API.md#routerallowedmethodsoptions--function

const Koa = require('koa');
const Router = require('@koa/router');
const Boom = require('boom');

const app = new Koa();
const router = new Router();

router.get('/ping', async ctx => {
  ctx.body = 'PONG!'
})

app.use(router.routes());
app.use(router.allowedMethods({
  throw: true,
  notImplemented: () => new Boom.notImplemented(),
  methodNotAllowed: () => new Boom.methodNotAllowed()
}));
app.listen(8080)

Expected Behavior:

Should "just work" and give me 501 NOT IMPLEMENTED when I call a route that doesn't an HTTP method implemented

Actual Behavior:

500 Internal Error

Console output:

  TypeError: Boom.methodNotAllowed is not a constructor

Additional steps, HTTP request details, or to reproduce the behavior or a test case:

curl -X POST -I http://localhost:8080/ping

This is an issue with Boom, as shown it says Boom.methodNowAllowed is not a constructor. So that's not a method. I think the new API for Boom is different -- go check their latest docs?. Note that Boom is now @hapi/boom I think, and the usage is a bit different.

@niftylettuce but I didn't get the coffee example above from hapi's docs. As I noted, this is in koa-router's docs 🤔

Sure.. can we reopen this and I'll make a PR off it?

just reference it in the commit message and stuff

Thanks again!