1
0
Fork 0
mirror of synced 2024-09-03 11:11:49 +12:00

Handle errors

This commit is contained in:
Adria Navarro 2023-06-13 17:08:33 +01:00
parent f3b461a62c
commit 3d01775b89
3 changed files with 23 additions and 7 deletions

View file

@ -120,12 +120,24 @@ export async function decryptFile(
const stretched = stretchString(secret, salt) const stretched = stretchString(secret, salt)
const decipher = crypto.createDecipheriv(ALGO, stretched, iv) const decipher = crypto.createDecipheriv(ALGO, stretched, iv)
inputFile.pipe(decipher).pipe(zlib.createGunzip()).pipe(outputFile) const unzip = zlib.createGunzip()
return new Promise<void>(r => { inputFile.pipe(decipher).pipe(unzip).pipe(outputFile)
outputFile.on("finish", () => {
return new Promise<void>((res, rej) => {
inputFile.on("finish", () => {
outputFile.close() outputFile.close()
r() res()
})
decipher.on("error", e => {
outputFile.close()
rej(e)
})
unzip.on("error", e => {
outputFile.close()
rej(e)
}) })
}) })
} }

View file

@ -17,6 +17,7 @@
import TemplateCard from "components/common/TemplateCard.svelte" import TemplateCard from "components/common/TemplateCard.svelte"
import createFromScratchScreen from "builderStore/store/screenTemplates/createFromScratchScreen" import createFromScratchScreen from "builderStore/store/screenTemplates/createFromScratchScreen"
import { Roles } from "constants/backend" import { Roles } from "constants/backend"
import { lowercase } from "helpers"
export let template export let template
@ -190,8 +191,11 @@
try { try {
await createNewApp() await createNewApp()
} catch (e) { } catch (e) {
console.log(e) let message = "Error creating app"
notifications.error("Error creating app") if (e.message) {
message += `: ${lowercase(e.message)}`
}
notifications.error(message)
return false return false
} }
}, },

View file

@ -134,7 +134,7 @@ async function decryptFiles(path: string, password: string) {
} }
} catch (err: any) { } catch (err: any) {
if (err.message === "incorrect header check") { if (err.message === "incorrect header check") {
throw new Error("Wrong password") throw new Error("File cannot be imported")
} }
throw err throw err
} }