mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 18:44:16 +00:00
use try&catch
This commit is contained in:
parent
5646510a22
commit
8cf613fbe6
@ -4,6 +4,7 @@ import axios from "axios"
|
||||
|
||||
export default async (payload) => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
try {
|
||||
let { url, destination } = payload
|
||||
|
||||
// if destination path is not provided, use cache folder
|
||||
@ -11,10 +12,7 @@ export default async (payload) => {
|
||||
destination = path.resolve(global.uploadCachePath, path.basename(url))
|
||||
}
|
||||
|
||||
const writer = fs.createWriteStream(destination).catch((err) => {
|
||||
reject(err)
|
||||
return false
|
||||
})
|
||||
const writer = fs.createWriteStream(destination)
|
||||
|
||||
if (!writer) {
|
||||
return false
|
||||
@ -34,5 +32,8 @@ export default async (payload) => {
|
||||
read: () => fs.readFileSync(destination),
|
||||
}))
|
||||
writer.on("error", reject)
|
||||
} catch (error) {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user