imp(core): detect and map HttpRequestError
MODIFY
codecov.yml
codecov.yml
@@ -4,4 +4,4 @@ coverage:
enabled: false
target: auto
threshold: 5%
- patch: no
+ patch: off

MODIFY
packages/core/src/http/error/http.error.effect.ts
packages/core/src/http/error/http.error.effect.ts
@@ -3,6 +3,15 @@ import { HttpErrorEffect } from '../effects/http.effects.interface';
import { HttpStatus } from '../http.interface';
import { HttpError, isHttpError } from './http.error.model';
+interface HttpErrorResponse {
+ error: {
+ status: HttpStatus;
+ message: string;
+ data?: any;
+ context?: string;
+ };
+}
+
const defaultHttpError = new HttpError(
'Internal server error',
HttpStatus.INTERNAL_SERVER_ERROR,
@@ -13,16 +22,17 @@ const getStatusCode = (error: Error): HttpStatus =>
? error.status
: HttpStatus.INTERNAL_SERVER_ERROR;
-const errorFactory = (status: HttpStatus, error: Error) =>
- isHttpError(error)
- ? { error: { status, message: error.message, data: error.data, context: error.context } }
- : { error: { status, message: error.message } };
+const errorFactory = (status: HttpStatus) => (error: Error): HttpErrorResponse => ({
+ error: isHttpError(error)
+ ? { status, message: error.message, data: error.data, context: error.context }
+ : { status, message: error.message },
+})
export const defaultError$: HttpErrorEffect = req$ =>
req$.pipe(
map(({ error = defaultHttpError }) => {
const status = getStatusCode(error);
- const body = errorFactory(status, error);
+ const body = errorFactory(status)(error);
return { status, body };
}),
);

MODIFY
packages/core/src/http/router/http.router.resolver.v2.ts
packages/core/src/http/router/http.router.resolver.v2.ts
@@ -9,6 +9,7 @@ import {
unexpectedErrorWhileSendingOutputFactory,
errorNotBoundToRequestErrorFactory,
responseNotBoundToRequestErrorFactory,
+ isHttpRequestError,
} from '../error/http.error.model';
import { useContext } from '../../context/context.hook';
import { HttpRequestBusToken } from '../server/http.server.tokens';
@@ -46,6 +47,7 @@ export const resolveRouting = (
const errorFlow$ = errorSubject.asObservable().pipe(
takeUntil(close$),
+ map(data => isHttpRequestError(data.error) ? { ...data, error: data.error } : data),
mergeMap(data => {
const stream = error$ ? error$(of(data), ctx) : defaultError$(of(data), ctx);
return stream.pipe(
@@ -94,19 +96,13 @@ export const resolveRouting = (
const subscribe = (stream$: Observable<HttpEffectResponse>) =>
stream$.subscribe(
res => {
- if (res.request) {
+ if (!res.request) throw responseNotBoundToRequestErrorFactory(res);
outputSubject.next({ res, req: res.request });
- } else {
- throw responseNotBoundToRequestErrorFactory(res);
- }
},
error => {
- if (error.request) {
+ if (!error.request) throw errorNotBoundToRequestErrorFactory(error);
errorSubject.next({ error, req: error.request });
subscribe(stream$);
- } else {
- throw errorNotBoundToRequestErrorFactory(error);
- }
},
);

imp(core): detect and map HttpRequestError