Initial commit: Supermarket scraper MVP
This commit is contained in:
29
src/utils/errors.ts
Normal file
29
src/utils/errors.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
export class ScraperError extends Error {
|
||||
constructor(
|
||||
message: string,
|
||||
public readonly code?: string,
|
||||
public readonly statusCode?: number
|
||||
) {
|
||||
super(message);
|
||||
this.name = 'ScraperError';
|
||||
}
|
||||
}
|
||||
|
||||
export class DatabaseError extends Error {
|
||||
constructor(message: string, public readonly originalError?: Error) {
|
||||
super(message);
|
||||
this.name = 'DatabaseError';
|
||||
}
|
||||
}
|
||||
|
||||
export class APIError extends Error {
|
||||
constructor(
|
||||
message: string,
|
||||
public readonly statusCode: number,
|
||||
public readonly response?: any
|
||||
) {
|
||||
super(message);
|
||||
this.name = 'APIError';
|
||||
}
|
||||
}
|
||||
|
||||
20
src/utils/logger.ts
Normal file
20
src/utils/logger.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
export class Logger {
|
||||
static info(message: string, ...args: any[]) {
|
||||
console.log(`[INFO] ${new Date().toISOString()} - ${message}`, ...args);
|
||||
}
|
||||
|
||||
static error(message: string, ...args: any[]) {
|
||||
console.error(`[ERROR] ${new Date().toISOString()} - ${message}`, ...args);
|
||||
}
|
||||
|
||||
static warn(message: string, ...args: any[]) {
|
||||
console.warn(`[WARN] ${new Date().toISOString()} - ${message}`, ...args);
|
||||
}
|
||||
|
||||
static debug(message: string, ...args: any[]) {
|
||||
if (process.env.DEBUG === 'true') {
|
||||
console.log(`[DEBUG] ${new Date().toISOString()} - ${message}`, ...args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user