imp(core): pipe `Route not found` routing fallback through `error$`
MODIFY
packages/core/src/listener/http.listener.ts
packages/core/src/listener/http.listener.ts
@@ -7,11 +7,12 @@ import {
HttpErrorEffect,
HttpOutputEffect,
} from '../effects/http-effects.interface';
-import { HttpRequest, HttpResponse, HttpStatus } from '../http.interface';
+import { HttpRequest, HttpResponse } from '../http.interface';
import { handleResponse } from '../response/response.handler';
import { RouteEffect, RouteEffectGroup, RoutingItem } from '../router/router.interface';
import { resolveRouting } from '../router/router.resolver.v2';
import { factorizeRoutingWithDefaults } from '../router/router.factory';
+import { ROUTE_NOT_FOUND_ERROR } from '../router/router.effects';
import { Context, lookup } from '../context/context.factory';
import { createEffectContext } from '../effects/effectsContext.factory';
import { useContext } from '../context/context.hook';
@@ -42,7 +43,7 @@ export const httpListener = ({
const effectContext = createEffectContext({ ask, client });
const middleware$ = combineMiddlewares(...middlewares);
const routing = factorizeRoutingWithDefaults(effects);
- const { resolve, outputSubject } = resolveRouting(routing, effectContext)(middleware$, output$, error$);
+ const { resolve, errorSubject } = resolveRouting(routing, effectContext)(middleware$, output$, error$);
const httpServer = (req: IncomingMessage, res: OutgoingMessage) => {
const marbleReq = req as HttpRequest;
@@ -51,12 +52,12 @@ export const httpListener = ({
marbleRes.send = handleResponse(marbleRes)(marbleReq);
marbleReq.response = marbleRes;
- const subject = resolve(marbleReq);
+ const routeSubject = resolve(marbleReq);
- if (subject) {
- subject.next(marbleReq);
+ if (routeSubject) {
+ routeSubject.next(marbleReq);
} else {
- outputSubject.next({ req: marbleReq, res: { status: HttpStatus.NOT_FOUND }});
+ errorSubject.next({ req: marbleReq, error: ROUTE_NOT_FOUND_ERROR });
}
};

MODIFY
packages/core/src/router/router.effects.ts
packages/core/src/router/router.effects.ts
@@ -4,11 +4,11 @@ import { r } from './router.ixbuilder';
import { HttpError } from '../error/error.model';
import { HttpStatus } from '../http.interface';
+export const ROUTE_NOT_FOUND_ERROR = new HttpError('Route not found', HttpStatus.NOT_FOUND);
+
export const notFound$ = r.pipe(
r.matchPath('*'),
r.matchType('*'),
r.useEffect(req$ => req$.pipe(
- mergeMap(() => throwError(
- new HttpError('Route not found', HttpStatus.NOT_FOUND)
- )),
+ mergeMap(() => throwError(ROUTE_NOT_FOUND_ERROR)),
)));

imp(core): pipe `Route not found` routing fallback through `error$`