Refactored to typescript & more consistent code

Updated how we interface with figlet and unified error handling &
response.
This commit is contained in:
2022-11-02 21:14:12 +01:00
parent df172e94ea
commit c8f87ade58
19 changed files with 1442 additions and 115 deletions

47
src/errors.ts Normal file
View File

@@ -0,0 +1,47 @@
class MissingTextError extends Error {
error: string
statusCode: number
constructor(error = null) {
const message = `Missing query parameter 'text'.`;
super(message);
this.error = error;
this.statusCode = 400;
}
}
class FontNotFoundError extends Error {
error: string
statusCode: number
constructor(font, error = null) {
const message = `Font '${font}' not found. Check /fonts.`;
super(message);
this.error = error;
this.statusCode = 404;
}
}
class UnexpectedFigletError extends Error {
error: string
statusCode: number
constructor(error) {
const message = "Unexpected error from figlet!"
super(message)
this.error = error;
this.statusCode = 500
console.log(message)
console.log(error)
}
}
export {
MissingTextError,
FontNotFoundError,
UnexpectedFigletError
};