Improving error messages

This commit is contained in:
Fabian Stamm 2020-09-14 23:47:48 +02:00
parent dd1d8e0947
commit 66b430ac90
3 changed files with 14 additions and 5 deletions

View File

@ -1,5 +1,6 @@
import { Colors, Path, FS, Compress, Base64 } from "../deps.ts";
import { getMeta, IMeta, log, getConfig } from "../global.ts";
import { ServerError } from "../helper/server_error.ts";
async function runScript(script: string) {
console.log(Colors.bold(Colors.blue("Running script:")), script);
@ -104,17 +105,20 @@ export default async function publish(options: { dry: boolean }) {
.then((res) =>
res.status === 200
? res.json()
: Promise.reject(new Error(res.statusText))
: Promise.reject(new ServerError(res.statusText))
)
.then((res) => {
if (!res.success) {
throw new Error(res.message);
throw new ServerError(res.message);
} else {
console.log(Colors.green("Upload successfull"));
}
})
.catch((err) => {
console.log(Colors.red("Error: " + err.message));
//import { ServerError } from "../helper/server_error.ts";
if (err instanceof ServerError)
console.log(Colors.red("Server Error: " + err.message));
else console.log(Colors.red("Error: " + err.message));
});
} else {
console.log(Colors.yellow("Dry run. Skipping upload"));

View File

@ -1,6 +1,6 @@
export * as Compress from "https://deno.hibas123.de/raw/@denreg-tar/mod.ts";
export * as Ini from "https://deno.land/x/ini/mod.ts";
export * as Cliffy from "https://deno.land/x/cliffy/mod.ts";
export * as Ini from "https://deno.land/x/ini@v2.1.0/mod.ts";
export * as Cliffy from "https://deno.land/x/cliffy@v0.14.1/mod.ts";
export * as Base64 from "https://deno.land/std@0.65.0/encoding/base64.ts";
export * as FS from "https://deno.land/std@0.65.0/fs/mod.ts";
export * as Colors from "https://deno.land/std@0.65.0/fmt/colors.ts";

View File

@ -0,0 +1,5 @@
export class ServerError extends Error {
constructor(message: string) {
super(message);
}
}