minor refactor of router to use explicit exceptions
[squeep-api-dingus] / lib / router / index.js
index 1585065e14ce79b804cd6de967965951ab0d535a..fd19bdf5192cfd9efd7b4c00023f1ae92265cbd1 100644 (file)
@@ -7,7 +7,7 @@
 
 const { METHODS: httpMethods } = require('http');
 const common = require('../common');
-const { DingusError } = require('../errors');
+const { DingusError, RouterNoPathError, RouterNoMethodError } = require('../errors');
 const PathParameter = require('./path-parameter');
 
 // Internal identifiers for route entries.
@@ -266,10 +266,10 @@ class Router {
       if ('*' in matchedPath[kPathMethods]) {
         return matchedPath[kPathMethods]['*'];
       }
-      throw new DingusError('NoMethod');
+      throw new RouterNoMethodError();
     }
     ctx.unmatchedPath = pathParts;
-    throw new DingusError('NoPath');
+    throw new RouterNoPathError();
   }