UNPKG

@stacksjs/error-handling

Version:
31 lines (30 loc) 1.19 kB
import * as path from '@stacksjs/path'; import type { LogErrorOptions } from '@stacksjs/logging'; // Function to update the default log path when config is available export declare function setLogPath(path: string): void; export declare function writeToLogFile(message: string, options?: WriteOptions): Promise<void>; export declare function handleError(err: string | Error | object | unknown, options?: unknown): Error; /** * Context information attached to errors for better debugging. */ export declare interface ErrorContext { requestId?: string url?: string method?: string userId?: string | number ip?: string userAgent?: string [key: string]: unknown } declare interface WriteOptions { logFile?: string } declare type ErrorMessage = string; export declare class ErrorHandler { static isTestEnvironment: boolean; static shouldExitProcess: boolean; static handle(err: Error | ErrorMessage | unknown, options?: LogErrorOptions): Error; static handleError(err: Error, options?: LogErrorOptions): Error; static writeErrorToFile(err: Error | unknown, context?: ErrorContext): Promise<void>; static writeErrorToConsole(err: string | Error | unknown): void; }