execute method
Execute request
Implementation
FutureOr<Response> execute(
Route route,
Request request,
String context,
) async {
final groups = route.getGroups();
final pathValues = route.getPathValues(request);
try {
await _executeHooks(
_init,
groups,
(hook) async => _getArguments(
hook,
context: context,
requestParams: await request.getParams(),
values: pathValues,
),
globalHook: route.hook,
);
final args = _getArguments(
route,
context: context,
requestParams: await request.getParams(),
values: pathValues,
);
final response = await Function.apply(
route.getAction(),
[...route.argsOrder.map((key) => args[key])],
);
await _executeHooks(
_shutdown,
groups,
(hook) async => _getArguments(
hook,
context: context,
requestParams: await request.getParams(),
values: pathValues,
),
globalHook: route.hook,
globalHooksFirst: false,
);
return response ?? getResource<Response>('response', context: context);
} on Exception catch (e) {
_di.set('error', () => e);
await _executeHooks(
_errors,
groups,
(hook) async => _getArguments(
hook,
context: context,
requestParams: await request.getParams(),
values: pathValues,
),
globalHook: route.hook,
globalHooksFirst: false,
);
if (e is ValidationException) {
final response = getResource<Response>('response', context: context);
response.status = 400;
}
}
return getResource<Response>('response', context: context);
}