Skip to content

Commit e4ad578

Browse files
committed
fix: #19 fix error guard and mapResponse method
1 parent cd0944b commit e4ad578

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

api/src/core/controller.core.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ export const getRequestUser = (data: unknown, ctx: ExecutionContext) => {
6969
};
7070
export const User = createParamDecorator(getRequestUser);
7171

72-
export function mapResponse<T, EI extends BaseError<unknown>, EO>(data: T | EI) {
72+
export function mapResponse<T, EI, EO>(data: T | BaseError<EI>) {
7373
return async (
74-
onData: (data: Exclude<T, EI>) => ControllerResponse | Promise<ControllerResponse>,
75-
onError?: (e: EI) => BaseError<EO> | Promise<BaseError<EO>>,
74+
onData: (data: T) => ControllerResponse | Promise<ControllerResponse>,
75+
onError?: (e: BaseError<EI>) => BaseError<EO> | Promise<BaseError<EO>>,
7676
) =>
7777
isError(data)
7878
? onError
7979
? Promise.resolve(onError(data))
8080
: Promise.resolve(data)
81-
: Promise.resolve(onData(data as Exclude<T, EI>));
81+
: Promise.resolve(onData(data));
8282
}

api/src/core/errors.core.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export class BaseError<E> {
4040
}
4141
}
4242

43-
export function isError<T, E>(value: T | BaseError<E>): value is BaseError<E> {
43+
export function isError<T, E, BE extends BaseError<E>>(value: T | BE): value is BE {
4444
return value instanceof BaseError;
4545
}
4646

0 commit comments

Comments
 (0)