1
0
Fork 0
mirror of synced 2024-09-29 16:51:33 +13:00

returning 400 error with message to be handled by frontend

This commit is contained in:
NEOLPAR 2022-09-06 16:37:37 +01:00
parent 62501bbef7
commit dbbb7f56f6

View file

@ -55,27 +55,23 @@ export async function upload(ctx: any) {
export async function create(ctx: any) {
const { type, source, url, headers, githubToken } = ctx.request.body
if (!env.SELF_HOSTED) {
ctx.throw(400, "Plugins not supported outside of self-host.")
}
try {
let metadata
let directory
// Generating random name as a backup and needed for url
let name = "PLUGIN_" + Math.floor(100000 + Math.random() * 900000)
if (!env.SELF_HOSTED) {
throw new Error("Plugins not supported outside of self-host.")
}
switch (source) {
case "npm":
try {
const { metadata: metadataNpm, directory: directoryNpm } =
await uploadedNpmPlugin(url, name)
metadata = metadataNpm
directory = directoryNpm
} catch (err: any) {
const errMsg = err?.message ? err?.message : err
ctx.throw(400, `Failed to import plugin: ${errMsg}`)
}
break
case "github":
const { metadata: metadataGithub, directory: directoryGithub } =
@ -91,7 +87,6 @@ export async function create(ctx: any) {
break
}
try {
const doc = await storePlugin(metadata, directory, source)
ctx.body = {