diff --git a/cli/commands/publish.ts b/cli/commands/publish.ts index 429475f..17f625f 100644 --- a/cli/commands/publish.ts +++ b/cli/commands/publish.ts @@ -44,7 +44,7 @@ export default async function publish() { log("Uploading new package version"); - const res = await fetch(url, { + await fetch(url, { method: "POST", body: await Deno.readFile(packedFile), headers: { @@ -54,19 +54,22 @@ export default async function publish() { getConfig("username") + ":" + getConfig("password") ), }, - }).then((res) => (res.status === 200 ? res.json() : res.statusText)); - - log("Upload finished. Result:", res); - - if (typeof res === "string" || res.error) { - console.log( - Colors.red("Error: " + (typeof res == "string" ? res : res.error)) - ); - } else { - if (res.success) { - console.log(Colors.green("Upload successfull")); - } - } + }) + .then((res) => + res.status === 200 + ? res.json() + : Promise.reject(new Error("res.statusText")) + ) + .then((res) => { + if (!res.success) { + throw new Error(res.message); + } else { + console.log(Colors.green("Upload successfull")); + } + }) + .catch((err) => { + console.log(Colors.red("Error: " + err.message)); + }); } finally { await Deno.remove(tmpDir, { recursive: true }); await Deno.remove(packedFile); diff --git a/cli/meta.json b/cli/meta.json index 75b46d0..c43bfb5 100644 --- a/cli/meta.json +++ b/cli/meta.json @@ -1,8 +1,12 @@ { "name": "@denreg-cli", - "version": "0.1.2", + "version": "0.1.4", "description": "CLI for the DenReg package registry", "author": "Fabian Stamm ", "contributors": [], - "files": ["**/*.ts", "**/*.js", "README.md"] -} + "files": [ + "**/*.ts", + "**/*.js", + "README.md" + ] +} \ No newline at end of file