X-Git-Url: http://git.squeep.com/?p=squeep-api-dingus;a=blobdiff_plain;f=lib%2Fdingus.js;fp=lib%2Fdingus.js;h=484debced43f0732a71ca0967d964b6475256a29;hp=5b4643c6b2e79c641c3604910c0a3397be56da6b;hb=91ca5d0b0e93afeb5c68a48fef461bbcc095fcbe;hpb=364087437981d41c2dfb1b20ff2260f1edc0920f diff --git a/lib/dingus.js b/lib/dingus.js index 5b4643c..484debc 100644 --- a/lib/dingus.js +++ b/lib/dingus.js @@ -13,7 +13,7 @@ const querystring = require('querystring'); const common = require('./common'); const ContentNegotiation = require('./content-negotiation'); const Enum = require('./enum'); -const { DingusError, ResponseError } = require('./errors'); +const { DingusError, ResponseError, RouterNoMethodError, RouterNoPathError } = require('./errors'); const { extensionToMime } = require('./mime-helper'); const Router = require('./router'); const Template = require('./template'); @@ -268,18 +268,13 @@ class Dingus { try { ({ handler, handlerArgs } = this.router.lookup(req.method, pathPart, ctx)); } catch (e) { - if (e instanceof DingusError) { - switch (e.message) { - case 'NoPath': - handler = this.handlerNotFound.bind(this); - break; - case 'NoMethod': - handler = this.handlerMethodNotAllowed.bind(this); - break; - default: - this.logger.error(_scope, 'unknown dingus error', { error: e }); - handler = this.handlerInternalServerError.bind(this); - } + if (e instanceof RouterNoPathError) { + handler = this.handlerNotFound.bind(this); + } else if (e instanceof RouterNoMethodError) { + handler = this.handlerMethodNotAllowed.bind(this); + } else if (e instanceof DingusError) { + this.logger.error(_scope, 'unknown dingus error', { error: e }); + handler = this.handlerInternalServerError.bind(this); } else if (e instanceof URIError) { handler = this.handlerBadRequest.bind(this); } else {