handleEdgeFetch<E extends Variables> function
Runs app against raw and produces a web.Response.
For use by adapter packages implementing a runtime's fetch entry point. Two fallbacks keep a broken request or response from crashing the isolate:
- If Aim.handle throws, logs to
console.errorand answers 400. - If toWebResponse throws, logs to
console.errorand answers 500.
Unhandled errors inside a handler (with no Aim.onError registered) are
caught by Aim.handle's onUnhandledError, logged, and answered as 500.
Implementation
Future<web.Response> handleEdgeFetch<E extends Variables>(
Aim<E> app,
EdgeRaw raw,
) async {
Response response;
try {
response = await app.handle(
await toAimRequest(raw),
onUnhandledError: _logAndRespond,
);
} catch (e, st) {
web.console.error('Failed to process request: $e\n$st'.toJS);
response = Response.text('Bad Request', statusCode: 400);
}
try {
return toWebResponse(response);
} catch (e, st) {
web.console.error('Failed to send response: $e\n$st'.toJS);
return web.Response(
'Internal Server Error'.toJS,
web.ResponseInit(status: 500),
);
}
}