Catch all upload errors
This commit is contained in:
@@ -680,6 +680,7 @@ export type UploadFileResult = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const uploadFile = async (file: File, options: UploadFileOptions = {}) => {
|
export const uploadFile = async (file: File, options: UploadFileOptions = {}) => {
|
||||||
|
try {
|
||||||
const {name, type} = file
|
const {name, type} = file
|
||||||
|
|
||||||
if (!type.match("image/(webp|gif)")) {
|
if (!type.match("image/(webp|gif)")) {
|
||||||
@@ -707,8 +708,6 @@ export const uploadFile = async (file: File, options: UploadFileOptions = {}) =>
|
|||||||
const $signer = signer.get() || Nip01Signer.ephemeral()
|
const $signer = signer.get() || Nip01Signer.ephemeral()
|
||||||
const authTemplate = makeBlossomAuthEvent({action: "upload", server, hashes})
|
const authTemplate = makeBlossomAuthEvent({action: "upload", server, hashes})
|
||||||
const authEvent = await $signer.sign(authTemplate)
|
const authEvent = await $signer.sign(authTemplate)
|
||||||
|
|
||||||
try {
|
|
||||||
const res = await uploadBlob(server, file, {authEvent})
|
const res = await uploadBlob(server, file, {authEvent})
|
||||||
const text = await res.text()
|
const text = await res.text()
|
||||||
|
|
||||||
@@ -727,7 +726,8 @@ export const uploadFile = async (file: File, options: UploadFileOptions = {}) =>
|
|||||||
|
|
||||||
return {result}
|
return {result}
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
console.error(e)
|
console.error("Error caught when uploading file:", e)
|
||||||
|
|
||||||
return {error: e.toString()}
|
return {error: e.toString()}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user