UNPKG

express-ai-error-handler

Version:
30 lines (29 loc) 1.04 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const express_1 = __importDefault(require("express")); const app_1 = __importDefault(require("../src/app")); const app = (0, express_1.default)(); const PORT = 3000; const apiKeys = [ 'AIzaSyBhwCvQDSG-IF1cIWfwh05Lu-FlvJXqkRc', 'AIzaSyCBxpd6hbxvrFfTX1lOv91nFD6-7z9nXtE', 'AIzaSyAGq8jCCKcSyuNYX-FqrWinsvUNqv4Bey4', ]; // Initialize AIErrorHandler with options const errorHandler = new app_1.default(apiKeys, { defaultMessage: "Something went wrong, please try again.", model: "gemini-1.5-flash", maxTokens: 100, }); // Middleware to simulate an error app.get("/", (_req, _res, next) => { next(new Error("Example API error occurred!")); }); // Use AI-powered error handler app.use(errorHandler.middleware()); app.listen(PORT, () => { console.log(`Server running on http://localhost:${PORT}`); });