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:
parent
06851d9961
commit
8fc922407f
@ -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);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user