Remove throw from log function

- Typescript cannot determine if a function throws an error
- Does not work as a type guard when using ts-rest
This commit is contained in:
jeffvli 2023-12-03 22:15:03 -08:00
parent 509627a0ad
commit 3b155cc6e8

View File

@ -1,4 +1,3 @@
import console from 'console';
import dayjs from 'dayjs';
const reset = '\x1b[0m';
@ -23,19 +22,10 @@ const baseLog = (errorType: 'error' | 'info' | 'success' | 'warn') => {
break;
}
return (
text: string,
options?: { context?: Record<string, any>; throwError?: boolean; toast?: boolean },
): null | Error => {
const { throwError } = options || {};
return (text: string, options?: { context?: Record<string, any>; toast?: boolean }): void => {
// const { toast } = options || {};
const now = dayjs().toISOString();
console.log(`${logString}${now}${text}${JSON.stringify(options?.context)}${reset}`);
if (!throwError) {
return null;
}
throw new Error(text);
};
};