style(core): separated http and non http error types
MODIFY
packages/core/src/error/error.model.ts
packages/core/src/error/error.model.ts
import { Event } from '../event/event.interface';
-import { HttpStatus } from '../http/http.interface';
import { ExtendableError } from '../+internal/utils';
export enum ErrorType {
CORE_ERROR = 'CoreError',
CONTEXT_ERROR = 'ContextError',
- HTTP_ERROR = 'HttpError',
EVENT_ERROR = 'EventError',
}
-export class HttpError extends ExtendableError {
- constructor(
- public readonly message: string,
- public readonly status: HttpStatus,
- public readonly data?: object,
- public readonly context?: string,
- ) {
- super(ErrorType.HTTP_ERROR, message);
- }
-}
-
export class CoreError extends ExtendableError {
constructor(
public readonly message: string,
@@ -52,9 +39,6 @@ export class EventError extends ExtendableError {
}
}
-export const isHttpError = (error: Error): error is HttpError =>
- error.name === ErrorType.HTTP_ERROR;
-
export const isCoreError = (error: Error): error is CoreError =>
error.name === ErrorType.CORE_ERROR;

MODIFY
packages/core/src/error/specs/error.model.spec.ts
packages/core/src/error/specs/error.model.spec.ts
-import { HttpError, isHttpError, CoreError, isCoreError, EventError, isEventError } from '../error.model';
+import { CoreError, isCoreError, EventError, isEventError } from '../error.model';
describe('Error model', () => {
@@ -10,14 +10,6 @@ describe('Error model', () => {
jest.clearAllMocks();
});
- test('#HttpError creates error object', () => {
- const error = new HttpError('test-message', 200);
-
- expect(error.name).toBe('HttpError');
- expect(error.status).toBe(200);
- expect(error.message).toBe('test-message');
- });
-
test('#CoreError creates error object', () => {
// given
const stackTraceFactory = jest.fn();
@@ -42,14 +34,6 @@ describe('Error model', () => {
return;
});
- test('#isHttpError detects HttpError type', () => {
- const httpError = new HttpError('test-message', 200);
- const otherError = new Error();
-
- expect(isHttpError(httpError)).toBe(true);
- expect(isHttpError(otherError)).toBe(false);
- });
-
test('#isCoreError detects CoreError type', () => {
const coreError = new CoreError('test-message', {
context: {},

MODIFY
packages/core/src/http/error/http.error.effect.ts
packages/core/src/http/error/http.error.effect.ts
import { map } from 'rxjs/operators';
-import { HttpError, isHttpError } from '../../error/error.model';
import { HttpErrorEffect } from '../effects/http.effects.interface';
import { HttpStatus } from '../http.interface';
+import { HttpError, isHttpError } from './http.error.model';
const defaultHttpError = new HttpError(
'Internal server error',

ADD
packages/core/src/http/error/http.error.model.ts
+import { HttpStatus } from '../http.interface';
+import { ExtendableError } from '../../+internal/utils';
+
+export enum HttpErrorType {
+ HTTP_ERROR = 'HttpError',
+}
+
+export class HttpError extends ExtendableError {
+ constructor(
+ public readonly message: string,
+ public readonly status: HttpStatus,
+ public readonly data?: object,
+ public readonly context?: string,
+ ) {
+ super(HttpErrorType.HTTP_ERROR, message);
+ }
+}
+
+export const isHttpError = (error: Error): error is HttpError =>
+ error.name === HttpErrorType.HTTP_ERROR;

MODIFY
packages/core/src/http/error/specs/http.error.effect.spec.ts
packages/core/src/http/error/specs/http.error.effect.spec.ts
import { Marbles, createHttpResponse, createHttpRequest } from '../../../+internal';
import { defaultError$ } from '../http.error.effect';
-import { HttpError } from '../../../error/error.model'; // @TODO: move to 'http' folder
+import { HttpError } from '../http.error.model';
describe('defaultError$', () => {
const req = createHttpRequest();

ADD
packages/core/src/http/error/specs/http.error.model.spec.ts
+import { HttpError, isHttpError } from '../http.error.model';
+
+describe('Http error model', () => {
+
+ test('#HttpError creates error object', () => {
+ const error = new HttpError('test-message', 200);
+
+ expect(error.name).toBe('HttpError');
+ expect(error.status).toBe(200);
+ expect(error.message).toBe('test-message');
+ });
+
+ test('#isHttpError detects HttpError type', () => {
+ const httpError = new HttpError('test-message', 200);
+ const otherError = new Error();
+
+ expect(isHttpError(httpError)).toBe(true);
+ expect(isHttpError(otherError)).toBe(false);
+ });
+
+});

MODIFY
packages/core/src/http/router/http.router.effects.ts
packages/core/src/http/router/http.router.effects.ts
import { throwError } from 'rxjs';
import { mergeMapTo } from 'rxjs/operators';
-import { HttpError } from '../../error/error.model';
+import { HttpError } from '../error/http.error.model';
import { HttpStatus } from '../http.interface';
import { r } from './http.router.ixbuilder';

MODIFY
packages/core/src/index.ts
packages/core/src/index.ts
// http
export { EffectFactory } from './http/effects/http.effects.factory';
export { defaultError$ } from './http/error/http.error.effect';
+export { HttpError } from './http/error/http.error.model';
export { combineRoutes } from './http/router/http.router.combiner';
export { r } from './http/router/http.router.ixbuilder';
export * from './http/router/http.router.interface';
@@ -12,23 +13,23 @@ export * from './http/server/http.server.factory';
export * from './http/server/http.server.listener';
export * from './http/http.interface';
-// error
+// core - error
export { coreErrorFactory, CoreErrorOptions } from './error/error.factory';
-export { HttpError, CoreError, EventError } from './error/error.model';
+export { CoreError, EventError } from './error/error.model';
-// effects
+// core - effects
export { combineEffects, combineMiddlewares } from './effects/effects.combiner';
export { createEffectContext } from './effects/effectsContext.factory';
export * from './effects/effects.interface';
-// operators
+// core - operators
export * from './operators';
-// event
+// core - event
export * from './event/event.factory';
export * from './event/event.interface';
-// context
+// core - context
export * from './context/context.factory';
export * from './context/context.hook';
export * from './context/context.token.factory';

style(core): separated http and non http error types