mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-22 07:05:24 +00:00
support non-native promise implementations
This commit is contained in:
@@ -2,7 +2,7 @@ import { IGNORE } from '../placeholders';
|
|||||||
import { Req, Res, ServerRoute } from './types';
|
import { Req, Res, ServerRoute } from './types';
|
||||||
|
|
||||||
export function get_server_route_handler(routes: ServerRoute[]) {
|
export function get_server_route_handler(routes: ServerRoute[]) {
|
||||||
function handle_route(route: ServerRoute, req: Req, res: Res, next: () => void) {
|
async function handle_route(route: ServerRoute, req: Req, res: Res, next: () => void) {
|
||||||
req.params = route.params(route.pattern.exec(req.path));
|
req.params = route.params(route.pattern.exec(req.path));
|
||||||
|
|
||||||
const method = req.method.toLowerCase();
|
const method = req.method.toLowerCase();
|
||||||
@@ -53,12 +53,7 @@ export function get_server_route_handler(routes: ServerRoute[]) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = handle_method(req, res, handle_next);
|
await handle_method(req, res, handle_next);
|
||||||
|
|
||||||
// catch failures in async functions
|
|
||||||
if (Promise.resolve(result) === result) {
|
|
||||||
result.catch(handle_next);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
handle_next(err);
|
handle_next(err);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user