better error handle
This commit is contained in:
@@ -18,6 +18,13 @@ const api = axios.create({
|
|||||||
baseURL: API_ENDPOINT,
|
baseURL: API_ENDPOINT,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const throwErrors = async (res: any) => {
|
||||||
|
const errMsg = await res.json()
|
||||||
|
throw new Error(
|
||||||
|
`${errMsg.errors}\nPlease take a screenshot of the detailed error message in your terminal`
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export default async function inpaint(
|
export default async function inpaint(
|
||||||
imageFile: File,
|
imageFile: File,
|
||||||
settings: Settings,
|
settings: Settings,
|
||||||
@@ -92,8 +99,7 @@ export default async function inpaint(
|
|||||||
seed: res.headers.get("X-Seed"),
|
seed: res.headers.get("X-Seed"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const errors = await res.json()
|
await throwErrors(res)
|
||||||
throw new Error(`Something went wrong: ${errors.errors}`)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getServerConfig(): Promise<ServerConfig> {
|
export async function getServerConfig(): Promise<ServerConfig> {
|
||||||
@@ -143,8 +149,7 @@ export async function runPlugin(
|
|||||||
const blob = await res.blob()
|
const blob = await res.blob()
|
||||||
return { blob: URL.createObjectURL(blob) }
|
return { blob: URL.createObjectURL(blob) }
|
||||||
}
|
}
|
||||||
const errMsg = await res.json()
|
await throwErrors(res)
|
||||||
throw new Error(errMsg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getMediaFile(tab: string, filename: string) {
|
export async function getMediaFile(tab: string, filename: string) {
|
||||||
@@ -163,8 +168,7 @@ export async function getMediaFile(tab: string, filename: string) {
|
|||||||
})
|
})
|
||||||
return file
|
return file
|
||||||
}
|
}
|
||||||
const errMsg = await res.json()
|
await throwErrors(res)
|
||||||
throw new Error(errMsg.errors)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getMediaBlob(tab: string, filename: string) {
|
export async function getMediaBlob(tab: string, filename: string) {
|
||||||
@@ -180,8 +184,7 @@ export async function getMediaBlob(tab: string, filename: string) {
|
|||||||
const blob = await res.blob()
|
const blob = await res.blob()
|
||||||
return blob
|
return blob
|
||||||
}
|
}
|
||||||
const errMsg = await res.json()
|
await throwErrors(res)
|
||||||
throw new Error(errMsg.errors)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getMedias(tab: string): Promise<Filename[]> {
|
export async function getMedias(tab: string): Promise<Filename[]> {
|
||||||
@@ -204,8 +207,7 @@ export async function downloadToOutput(
|
|||||||
body: fd,
|
body: fd,
|
||||||
})
|
})
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
const errMsg = await res.text()
|
await throwErrors(res)
|
||||||
throw new Error(errMsg)
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new Error(`Something went wrong: ${error}`)
|
throw new Error(`Something went wrong: ${error}`)
|
||||||
@@ -245,6 +247,5 @@ export async function postAdjustMask(
|
|||||||
const blob = await res.blob()
|
const blob = await res.blob()
|
||||||
return blob
|
return blob
|
||||||
}
|
}
|
||||||
const errMsg = await res.json()
|
throwErrors(res)
|
||||||
throw new Error(errMsg)
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user