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

Extract minimal abstraction for specifically logging error instead of also warn, info, etc.

Co-authored-by: Janne Savolainen <janne.savolainen@live.fi>

Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
This commit is contained in:
Iku-turso 2022-06-21 13:30:50 +03:00
parent 2f4a409a1c
commit f56b48fea7
2 changed files with 17 additions and 4 deletions

View File

@ -0,0 +1,13 @@
/**
* Copyright (c) OpenLens Authors. All rights reserved.
* Licensed under MIT License. See LICENSE in root directory for more information.
*/
import { getInjectable } from "@ogre-tools/injectable";
import loggerInjectable from "./logger.injectable";
const logErrorInjectable = getInjectable({
id: "log-error",
instantiate: (di) => di.inject(loggerInjectable).error,
});
export default logErrorInjectable;

View File

@ -3,8 +3,8 @@
* Licensed under MIT License. See LICENSE in root directory for more information. * Licensed under MIT License. See LICENSE in root directory for more information.
*/ */
import { getInjectable } from "@ogre-tools/injectable"; import { getInjectable } from "@ogre-tools/injectable";
import loggerInjectable from "../../logger.injectable";
import { isPromise } from "../is-promise/is-promise"; import { isPromise } from "../is-promise/is-promise";
import logErrorInjectable from "../../log-error.injectable";
export type WithErrorLoggingFor = ( export type WithErrorLoggingFor = (
getErrorMessage: (error: unknown) => string getErrorMessage: (error: unknown) => string
@ -16,7 +16,7 @@ const withErrorLoggingInjectable = getInjectable({
id: "with-error-logging", id: "with-error-logging",
instantiate: (di): WithErrorLoggingFor => { instantiate: (di): WithErrorLoggingFor => {
const logger = di.inject(loggerInjectable); const logError = di.inject(logErrorInjectable);
return (getErrorMessage) => return (getErrorMessage) =>
(toBeDecorated) => (toBeDecorated) =>
@ -28,7 +28,7 @@ const withErrorLoggingInjectable = getInjectable({
returnValue.catch((e) => { returnValue.catch((e) => {
const errorMessage = getErrorMessage(e); const errorMessage = getErrorMessage(e);
logger.error(errorMessage, e); logError(errorMessage, e);
}); });
} }
@ -36,7 +36,7 @@ const withErrorLoggingInjectable = getInjectable({
} catch (e) { } catch (e) {
const errorMessage = getErrorMessage(e); const errorMessage = getErrorMessage(e);
logger.error(errorMessage, e); logError(errorMessage, e);
throw e; throw e;
} }