feat: errorMiddleware => errorEffect
MODIFY
packages/core/src/effects/effects.interface.ts
packages/core/src/effects/effects.interface.ts
@@ -9,7 +9,7 @@ export interface EffectResponse {
export type Middleware = Effect<HttpRequest>;
-export type ErrorMiddleware = Effect<EffectResponse, Error>;
+export type ErrorEffect = Effect<EffectResponse, Error>;
export type Effect<T = EffectResponse, U = any> = (
request$: Observable<HttpRequest>,

RENAME
packages/core/src/error/error.middleware.spec.ts
packages/core/src/error/error.effect.spec.ts
import { mapTo } from 'rxjs/operators';
import { Marbles } from '../../../util/marbles.spec-util';
import { HttpRequest, HttpResponse } from '../http.interface';
-import { error$, getErrorMiddleware } from './error.middleware';
+import { error$, errorEffectProvider } from './error.effect';
import { HttpError } from './error.model';
const createMockRes = () => ({} as HttpResponse);
const createMockReq = (url = '/') => ({ url } as HttpRequest);
-describe('Error middleware', () => {
+describe('Error effect', () => {
it('error$ maps HttpError', () => {
const error = new HttpError('test-message', 400);
@@ -41,15 +41,15 @@ describe('Error middleware', () => {
], { response: createMockRes(), error });
});
- it('#getErrorMiddleware provides middleware implementation', () => {
+ it('#errorEffectProvider provides error handler implementation', () => {
const customError$ = req$ => req$.pipe(mapTo({ status: 500, body: 'error' }));
- const middleware = getErrorMiddleware(customError$);
- expect(middleware).toBe(customError$);
+ const effect = errorEffectProvider(customError$);
+ expect(effect).toBe(customError$);
});
- it('#getErrorMiddleware provides default middleware implementation if not passed', () => {
- const middleware = getErrorMiddleware();
- expect(middleware).toBe(error$);
+ it('#errorEffectProvider provides default error handler implementation if not passed', () => {
+ const effect = errorEffectProvider();
+ expect(effect).toBe(error$);
});
});

RENAME
packages/core/src/error/error.middleware.ts
packages/core/src/error/error.effect.ts
@@ -5,7 +5,7 @@ import { HttpError, isHttpError } from './error.model';
export type ThrownError = HttpError & Error;
-export const getErrorMiddleware = (customError$?: Effect<EffectResponse, ThrownError>) => !!customError$
+export const errorEffectProvider = (customError$?: Effect<EffectResponse, ThrownError>) => !!customError$
? customError$
: error$;

MODIFY
packages/core/src/http.listener.spec.ts
packages/core/src/http.listener.spec.ts
@@ -3,10 +3,10 @@ import { of, throwError } from 'rxjs';
import { mapTo, switchMap } from 'rxjs/operators';
import { httpListener } from './http.listener';
import { EffectFactory } from './effects/effects.factory';
-import { Middleware, ErrorMiddleware } from './effects/effects.interface';
+import { Middleware, ErrorEffect } from './effects/effects.interface';
describe('Http listener', () => {
- let errorMiddleware;
+ let errorEffect;
let effectsCombiner;
let responseHandler;
let routerFactory;
@@ -18,16 +18,16 @@ describe('Http listener', () => {
.use(req$ => req$.pipe(mapTo( {} )));
const middleware$: Middleware = req$ => req$;
- const errorMiddleware$: ErrorMiddleware = req$ => req$.pipe(mapTo( {} ));
+ const errorMiddleware$: ErrorEffect = req$ => req$.pipe(mapTo( {} ));
beforeEach(() => {
- jest.unmock('./error/error.middleware.ts');
+ jest.unmock('./error/error.effect.ts');
jest.unmock('./effects/effects.combiner.ts');
jest.unmock('./response/response.handler.ts');
jest.unmock('./router/router.factory.ts');
jest.unmock('./router/router.ts');
- errorMiddleware = require('./error/error.middleware.ts');
+ errorEffect = require('./error/error.effect.ts');
effectsCombiner = require('./effects/effects.combiner.ts');
responseHandler = require('./response/response.handler.ts');
routerFactory = require('./router/router.factory.ts');
@@ -44,7 +44,7 @@ describe('Http listener', () => {
routerFactory.factorizeRouting = jest.fn(() => []);
router.resolveRouting = jest.fn(() => () => () => of({ body: 'test' }));
responseHandler.handleResponse = jest.fn(() => () => () => undefined);
- errorMiddleware.getErrorMiddleware = jest.fn(() => errorMiddleware$);
+ errorEffect.errorEffectProvider = jest.fn(() => errorMiddleware$);
httpListener({
middlewares: [middleware$],
@@ -68,7 +68,7 @@ describe('Http listener', () => {
// when
effectsCombiner.combineMiddlewareEffects = jest.fn(() => () => of(req));
routerFactory.factorizeRouting = jest.fn(() => []);
- errorMiddleware.getErrorMiddleware = jest.fn(() => errorMiddleware$);
+ errorEffect.errorEffectProvider = jest.fn(() => errorMiddleware$);
httpListener({
effects: [effect$],
@@ -90,7 +90,7 @@ describe('Http listener', () => {
routerFactory.factorizeRouting = jest.fn(() => []);
router.resolveRouting = jest.fn(() => () => () => of({ body: 'test' }).pipe(switchMap(() => throwError(error))));
responseHandler.handleResponse = jest.fn(() => () => () => undefined);
- errorMiddleware.getErrorMiddleware = jest.fn(() => errorHandler);
+ errorEffect.errorEffectProvider = jest.fn(() => errorHandler);
httpListener({
middlewares: [middleware$],

MODIFY
packages/core/src/http.listener.ts
packages/core/src/http.listener.ts
@@ -2,8 +2,8 @@ import { IncomingMessage, OutgoingMessage } from 'http';
import { Observable, of, Subject } from 'rxjs';
import { catchError, defaultIfEmpty, mergeMap, switchMap, tap, takeWhile } from 'rxjs/operators';
import { combineMiddlewareEffects } from './effects/effects.combiner';
-import { EffectResponse, Middleware, ErrorMiddleware } from './effects/effects.interface';
-import { getErrorMiddleware } from './error/error.middleware';
+import { EffectResponse, Middleware, ErrorEffect } from './effects/effects.interface';
+import { errorEffectProvider } from './error/error.effect';
import { Http, HttpRequest, HttpResponse, HttpStatus } from './http.interface';
import { handleResponse } from './response/response.handler';
import { RouteEffect, RouteEffectGroup } from './router/router.interface';
@@ -14,19 +14,19 @@ export { Observable };
type HttpListenerConfig = {
middlewares?: Middleware[];
effects: (RouteEffect | RouteEffectGroup)[];
- errorMiddleware?: ErrorMiddleware;
+ errorEffect?: ErrorEffect;
};
export const httpListener = ({
middlewares = [],
effects,
- errorMiddleware,
+ errorEffect,
}: HttpListenerConfig) => {
const request$ = new Subject<Http>();
const combinedMiddlewares = combineMiddlewareEffects(middlewares);
const routerEffects = factorizeRouting(effects);
- const providedErrorMiddleware = getErrorMiddleware(errorMiddleware);
+ const providedErrorEffect = errorEffectProvider(errorEffect);
const defaultResponse = { status: HttpStatus.NOT_FOUND } as EffectResponse;
const effect$ = request$.pipe(
@@ -39,7 +39,7 @@ export const httpListener = ({
defaultIfEmpty(defaultResponse),
tap(res.send),
catchError(error =>
- providedErrorMiddleware(of(req), res, error).pipe(
+ providedErrorEffect(of(req), res, error).pipe(
tap(res.send),
),
),

MODIFY
packages/core/src/index.ts
packages/core/src/index.ts
export { EffectFactory } from './effects/effects.factory';
-export { error$ } from './error/error.middleware';
+export { error$ } from './error/error.effect';
export { HttpError } from './error/error.model';
export { combineRoutes } from './router/router.factory';
export * from './effects/effects.interface';

feat: errorMiddleware => errorEffect