1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Export type for error logging

Co-authored-by: Mikko Aspiala <mikko.aspiala@gmail.com>

Signed-off-by: Janne Savolainen <janne.savolainen@live.fi>
This commit is contained in:
Janne Savolainen 2022-05-24 14:48:54 +03:00
parent 06851d9961
commit 8fc922407f
No known key found for this signature in database
GPG Key ID: 8C6CFB2FFFE8F68A

View File

@ -5,15 +5,21 @@
import { getInjectable } from "@ogre-tools/injectable";
import loggerInjectable from "../../logger.injectable";
export type WithErrorLoggingFor = (
getErrorMessage: (error: Error) => string
) => <T extends (...args: any[]) => any>(
toBeDecorated: T
) => (...args: Parameters<T>) => ReturnType<T>;
const withErrorLoggingInjectable = getInjectable({
id: "with-error-logging",
instantiate: (di) => {
instantiate: (di): WithErrorLoggingFor => {
const logger = di.inject(loggerInjectable);
return (getErrorMessage: (error: Error) => string) =>
<T extends (...args: any[]) => any>(toBeDecorated: T) =>
(...args: Parameters<T>): ReturnType<T> => {
return (getErrorMessage) =>
(toBeDecorated) =>
(...args) => {
try {
const returnValue = toBeDecorated(...args);