File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed
packages/pharaoh/lib/src/_next Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -132,17 +132,17 @@ abstract class ApplicationFactory {
132132
133133 static RequestHandler buildControllerMethod (ControllerMethod method) {
134134 final params = method.params;
135+ final methodName = method.methodName;
135136
136- return (req, res) {
137- final methodName = method.methodName;
137+ return (req, res) async {
138138 final instance = createNewInstance <HTTPController >(method.controller);
139139 final mirror = inject.reflect (instance);
140140
141141 mirror
142142 ..invokeSetter ('request' , req)
143143 ..invokeSetter ('response' , res);
144144
145- late Function () methodCall;
145+ Function methodCall;
146146
147147 if (params.isNotEmpty) {
148148 final args = _resolveControllerMethodArgs (req, method);
@@ -151,7 +151,12 @@ abstract class ApplicationFactory {
151151 methodCall = () => mirror.invoke (methodName, []);
152152 }
153153
154- return Future .sync (methodCall);
154+ try {
155+ final result = await methodCall.call ();
156+ return result is Response ? result : res.json (result);
157+ } on Response catch (response) {
158+ return response;
159+ }
155160 };
156161 }
157162
You can’t perform that action at this time.
0 commit comments