Skip to content

Commit

Permalink
fix checking errors AFTER handler is run
Browse files Browse the repository at this point in the history
  • Loading branch information
ridafkih committed May 12, 2022
1 parent 6fd1256 commit b8f64d5
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/util/routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ export const handleRoute = (controller: RouteController) => {
const [method, rule] = controllerRule as [MethodName, RouteHandlerRules];

const internalHandler = async (context: ExtendedContext) => {
const {
body = null,
code = 200,
headers = {},
} = await rule.handler(context);

const errors: string[] = (await rule.validation
?.validate(context.request?.body)
.catch(({ errors }: { errors: string[] }) => errors)) as string[];
Expand All @@ -26,6 +20,12 @@ export const handleRoute = (controller: RouteController) => {
return;
}

const {
body = null,
code = 200,
headers = {},
} = await rule.handler(context);

context.status = code;
(context as unknown as { body: object | unknown }).body = body;
for (const [key, value] of Object.entries(headers))
Expand Down

0 comments on commit b8f64d5

Please sign in to comment.