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

Refactor showing error notification

Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
Lauri Nevala 2022-01-03 16:48:35 +02:00
parent 2bc7757907
commit 8d52c43a71

View File

@ -63,7 +63,9 @@ export async function createTempFilesAndValidate({
const manifest = await validatePackage(tempFile);
if (!isCompatibleExtension(manifest)){
throw new Error("Incompatible extension");
displayError(fileName, { message: "Incompatible extension" });
return null;
}
const id = path.join(
@ -80,27 +82,31 @@ export async function createTempFilesAndValidate({
id,
};
} catch (error) {
const message = getMessageFromError(error);
logger.info(
`[EXTENSION-INSTALLATION]: installing ${fileName} has failed: ${message}`,
{ error },
);
Notifications.error(
<div className="flex column gaps">
<p>
Installing <em>{fileName}</em> has failed, skipping.
</p>
<p>
Reason: <em>{message}</em>
</p>
</div>,
);
displayError(fileName, error);
}
return null;
}
function displayError(fileName: string, error: any) {
const message = getMessageFromError(error);
logger.info(
`[EXTENSION-INSTALLATION]: installing ${fileName} has failed: ${message}`,
{ error },
);
Notifications.error(
<div className="flex column gaps">
<p>
Installing <em>{fileName}</em> has failed, skipping.
</p>
<p>
Reason: <em>{message}</em>
</p>
</div>,
);
}
function getExtensionPackageTemp(fileName = "") {
return path.join(os.tmpdir(), "lens-extensions", fileName);