Skip to content

Commit

Permalink
fix(common): remove catchAsync to let framework handle errors
Browse files Browse the repository at this point in the history
Signed-off-by: Romain Lenzotti <rom.lenzotti@gmail.com>
  • Loading branch information
Romakita committed Mar 14, 2024
1 parent 0a2caf4 commit ef7bfe8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 2 additions & 0 deletions packages/platform/common/src/services/PlatformHandler.spec.ts
Expand Up @@ -63,6 +63,7 @@ describe("PlatformHandler", () => {
});

const $ctx = PlatformTest.createRequestContext();
$ctx.endpoint = EndpointMetadata.get(Test, "get");

const result = service.createHandler(metadata);

Expand Down Expand Up @@ -271,6 +272,7 @@ describe("PlatformHandler", () => {
expect(handler).toHaveBeenCalled();
expect(middleware).toHaveBeenCalled();
});

it("should not call flush when is a stream", async () => {
@Injectable()
class TestService {
Expand Down
7 changes: 3 additions & 4 deletions packages/platform/common/src/services/PlatformHandler.ts
Expand Up @@ -64,7 +64,7 @@ export class PlatformHandler {
return async ($ctx: PlatformContext) => {
$ctx.handlerMetadata = handlerMetadata;

await catchAsyncError(() => this.onRequest(handler, $ctx));
await this.onRequest(handler, $ctx);

return this.next($ctx);
};
Expand Down Expand Up @@ -117,7 +117,7 @@ export class PlatformHandler {
return;
}

return $ctx.error ? $ctx.next($ctx.error) : $ctx.next();
return $ctx.next && $ctx.error ? $ctx.next($ctx.error) : $ctx.next();
}

/**
Expand Down Expand Up @@ -146,7 +146,6 @@ export class PlatformHandler {
const resolver = new AnyToPromiseWithCtx($ctx);

const {state, type, data, status, headers} = await resolver.call(handler);

// Note: restore previous handler metadata (for OIDC)
$ctx.handlerMetadata = handlerMetadata;

Expand Down Expand Up @@ -183,7 +182,7 @@ export class PlatformHandler {
}
} catch (error) {
$ctx.error = error;

// TODO on v8, we have to use platformExceptions.catch directly. Error middleware won't be supported anymore
throw error;
}
}
Expand Down

0 comments on commit ef7bfe8

Please sign in to comment.