summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/hero.mjs21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/hero.mjs b/src/hero.mjs
index a51d5c0..2355bbf 100644
--- a/src/hero.mjs
+++ b/src/hero.mjs
@@ -119,15 +119,22 @@ export const extractQueryParams = s => {
return ret;
};
+export const handle404 = _req => ({
+ status: 404,
+ body: "Not Found\n",
+});
+
+export const make404Handler = interceptors => ({
+ params: {},
+ handlerFn: wrapHandler(handle404, interceptors),
+});
+
export const handleRequest = async (table, method, url) => {
const [ path, queryParams ] = url.split("?");
- const handler = findHandler(table, method, path);
- if (!handler) {
- return {
- status: 404,
- body: "Not Found\n",
- };
- }
+ const handler = (
+ findHandler(table, method, path) ||
+ make404Handler(table.interceptors)
+ );
const request = {
params: {