mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-16 21:04:34 +00:00
Merge pull request #147 from sveltejs/gh-138
don't serve error page for unhandled server route errors
This commit is contained in:
@@ -234,9 +234,21 @@ function get_route_handler(chunks: Record<string, string>, routes: RouteObject[]
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
handler(req, res, () => {
|
const handle_error = (err?: Error) => {
|
||||||
handle_not_found(req, res, 404, 'Not found');
|
if (err) {
|
||||||
});
|
console.error(err.stack);
|
||||||
|
res.statusCode = 500;
|
||||||
|
res.end(err.message);
|
||||||
|
} else {
|
||||||
|
handle_not_found(req, res, 404, 'Not found');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
handler(req, res, handle_error);
|
||||||
|
} catch (err) {
|
||||||
|
handle_error(err);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// no matching handler for method — 404
|
// no matching handler for method — 404
|
||||||
handle_not_found(req, res, 404, 'Not found');
|
handle_not_found(req, res, 404, 'Not found');
|
||||||
@@ -294,7 +306,7 @@ function get_route_handler(chunks: Record<string, string>, routes: RouteObject[]
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
return function find_route(req: Req, res: ServerResponse, next: () => void) {
|
return function find_route(req: Req, res: ServerResponse) {
|
||||||
const url = req.pathname;
|
const url = req.pathname;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
3
test/app/routes/throw-an-error.js
Normal file
3
test/app/routes/throw-an-error.js
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export function get() {
|
||||||
|
throw new Error('nope');
|
||||||
|
}
|
||||||
@@ -391,6 +391,14 @@ function run(env) {
|
|||||||
JSON.parse(text);
|
JSON.parse(text);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('does not serve error page for non-page errors', () => {
|
||||||
|
return nightmare.goto(`${base}/throw-an-error`)
|
||||||
|
.page.text()
|
||||||
|
.then(text => {
|
||||||
|
assert.equal(text, 'nope');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('headers', () => {
|
describe('headers', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user