mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Add error logging to resolving of proxy
Co-authored-by: Janne Savolainen <janne.savolainen@live.fi> Signed-off-by: Iku-turso <mikko.aspiala@gmail.com>
This commit is contained in:
parent
fc0eb2c381
commit
7f6710d2f7
@ -4,14 +4,18 @@
|
|||||||
*/
|
*/
|
||||||
import { getInjectable } from "@ogre-tools/injectable";
|
import { getInjectable } from "@ogre-tools/injectable";
|
||||||
import electronInjectable from "./electron.injectable";
|
import electronInjectable from "./electron.injectable";
|
||||||
|
import withErrorLoggingInjectable from "../../../../common/utils/with-error-logging/with-error-logging.injectable";
|
||||||
|
|
||||||
const resolveProxyFromElectronInjectable = getInjectable({
|
const resolveProxyFromElectronInjectable = getInjectable({
|
||||||
id: "resolve-proxy-from-electron",
|
id: "resolve-proxy-from-electron",
|
||||||
|
|
||||||
instantiate: (di) => {
|
instantiate: (di) => {
|
||||||
const electron = di.inject(electronInjectable);
|
const electron = di.inject(electronInjectable);
|
||||||
|
const withErrorLoggingFor = di.inject(withErrorLoggingInjectable);
|
||||||
|
|
||||||
return async (url: string) => {
|
const withErrorLogging = withErrorLoggingFor(() => "Error resolving proxy");
|
||||||
|
|
||||||
|
return withErrorLogging(async (url: string) => {
|
||||||
const webContent = electron.webContents
|
const webContent = electron.webContents
|
||||||
.getAllWebContents()
|
.getAllWebContents()
|
||||||
.find((x) => !x.isDestroyed());
|
.find((x) => !x.isDestroyed());
|
||||||
@ -21,7 +25,7 @@ const resolveProxyFromElectronInjectable = getInjectable({
|
|||||||
}
|
}
|
||||||
|
|
||||||
return await webContent.session.resolveProxy(url);
|
return await webContent.session.resolveProxy(url);
|
||||||
};
|
});
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -10,16 +10,24 @@ import type { AsyncFnMock } from "@async-fn/jest";
|
|||||||
import asyncFn from "@async-fn/jest";
|
import asyncFn from "@async-fn/jest";
|
||||||
import type electron from "electron";
|
import type electron from "electron";
|
||||||
import { getPromiseStatus } from "../../../../common/test-utils/get-promise-status";
|
import { getPromiseStatus } from "../../../../common/test-utils/get-promise-status";
|
||||||
|
import logErrorInjectable from "../../../../common/log-error.injectable";
|
||||||
|
import type { DiContainer } from "@ogre-tools/injectable";
|
||||||
|
|
||||||
describe("technical: resolve-proxy-from-electron", () => {
|
describe("technical: resolve-proxy-from-electron", () => {
|
||||||
let resolveProxyMock: AsyncFnMock<(url: string) => Promise<string>>;
|
let resolveProxyMock: AsyncFnMock<(url: string) => Promise<string>>;
|
||||||
|
let logErrorMock: jest.Mock;
|
||||||
|
let di: DiContainer;
|
||||||
|
let actualPromise: Promise<string>;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
di = getDiForUnitTesting();
|
||||||
|
|
||||||
|
logErrorMock = jest.fn();
|
||||||
|
di.override(logErrorInjectable, () => logErrorMock);
|
||||||
|
});
|
||||||
|
|
||||||
describe("given there are non-destroyed Lens windows, when called with URL", () => {
|
describe("given there are non-destroyed Lens windows, when called with URL", () => {
|
||||||
let actualPromise: Promise<string>;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
const di = getDiForUnitTesting();
|
|
||||||
|
|
||||||
resolveProxyMock = asyncFn();
|
resolveProxyMock = asyncFn();
|
||||||
|
|
||||||
di.override(
|
di.override(
|
||||||
@ -82,12 +90,10 @@ describe("technical: resolve-proxy-from-electron", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("given there are only destroyed Lens windows, when called with URL, throws", () => {
|
describe("given there are only destroyed Lens windows, when called with URL", () => {
|
||||||
let actualPromise: Promise<string>;
|
let error: unknown;
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
const di = getDiForUnitTesting();
|
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
di.override(
|
di.override(
|
||||||
electronInjectable,
|
electronInjectable,
|
||||||
() =>
|
() =>
|
||||||
@ -114,13 +120,15 @@ describe("technical: resolve-proxy-from-electron", () => {
|
|||||||
resolveProxyFromElectronInjectable,
|
resolveProxyFromElectronInjectable,
|
||||||
);
|
);
|
||||||
|
|
||||||
actualPromise = resolveProxyFromElectron("some-url");
|
try {
|
||||||
|
await resolveProxyFromElectron("some-url");
|
||||||
|
} catch (e) {
|
||||||
|
error = e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it("rejects", () => {
|
it("logs error", () => {
|
||||||
return expect(actualPromise).rejects.toThrow(
|
expect(logErrorMock).toHaveBeenCalledWith("Error resolving proxy", error);
|
||||||
'Tried to resolve proxy for "some-url", but no browser window was available',
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user