Skip to content

Commit 56d8c58

Browse files
committed
chore: allow returning objects not response
1 parent 3a6caed commit 56d8c58

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

packages/pharaoh/lib/src/_next/core.dart

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)