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"));