mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-09 20:29:36 +02:00
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:
+2
-12
@@ -1,4 +1,3 @@
|
|||||||
import console from 'console';
|
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
const reset = '\x1b[0m';
|
const reset = '\x1b[0m';
|
||||||
@@ -23,19 +22,10 @@ const baseLog = (errorType: 'error' | 'info' | 'success' | 'warn') => {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (text: string, options?: { context?: Record<string, any>; toast?: boolean }): void => {
|
||||||
text: string,
|
// const { toast } = options || {};
|
||||||
options?: { context?: Record<string, any>; throwError?: boolean; toast?: boolean },
|
|
||||||
): null | Error => {
|
|
||||||
const { throwError } = options || {};
|
|
||||||
const now = dayjs().toISOString();
|
const now = dayjs().toISOString();
|
||||||
console.log(`${logString}${now}${text}${JSON.stringify(options?.context)}${reset}`);
|
console.log(`${logString}${now}${text}${JSON.stringify(options?.context)}${reset}`);
|
||||||
|
|
||||||
if (!throwError) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Error(text);
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user