refactor: cli

This commit is contained in:
Ruidy 2021-02-19 15:52:15 +01:00
parent 5a7dc56b51
commit 914ab13e74

View file

@ -1,4 +1,5 @@
import { readLines } from "https://deno.land/std@0.87.0/io/bufio.ts"; import { readLines } from "https://deno.land/std@0.87.0/io/bufio.ts";
import { ValidationError } from "./errors/exceptions.ts";
import { ID } from "./types/id.ts"; import { ID } from "./types/id.ts";
import { sayHello, sayRandomHello } from "./usecases/hello.ts"; import { sayHello, sayRandomHello } from "./usecases/hello.ts";
@ -17,8 +18,16 @@ const start = async () => {
} else if (value === "quit") { } else if (value === "quit") {
return; return;
} else { } else {
const id = new ID(parseInt(value, 10)); try {
console.log(sayHello(id)); const id = new ID(parseInt(value, 10));
console.log(sayHello(id));
} catch (error) {
if (error instanceof ValidationError) {
console.error(error.message);
} else {
throw error;
}
}
} }
} }
}; };