New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

express-ai-error-handler

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-ai-error-handler

AI-powered error handler for Express with AI failover support

latest
Source
npmnpm
Version
1.0.2
Version published
Weekly downloads
13
160%
Maintainers
1
Weekly downloads
 
Created
Source

Express AI Error Handler

GitHub license Blazing Fast gzip size Stable Release PRs Welcome

Overview

Express AI Error Handler is an Express middleware that intelligently handles API errors by providing AI-generated suggestions using Google Generative AI. This package helps developers troubleshoot API errors by offering guidance on the correct request format.

Features

  • AI-powered error handling for Express applications
  • Auto-suggestions for API request formatting
  • Supports multiple API keys with automatic failover
  • Configurable logging with Winston
  • Customizable AI model and response settings

Installation

Install via npm:

npm i express-ai-error-handler

Usage

Import and integrate AI Error Handler in your Express application:

import express from 'express'
import AIErrorHandler from 'express-ai-error-handler'

const app = express()
const errorHandler = new AIErrorHandler(['your-api-key'], {
	defaultMessage: 'Something went wrong. Please try again.',
	model: 'gemini-1.5-flash',
	maxTokens: 100,
	disableLogging: false,
})

app.use(errorHandler.middleware())

app.listen(3000, () => console.log('Server running on port 3000'))

API

new AIErrorHandler(apiKeys, options)

Creates a new instance of AI Error Handler.

Parameters:

  • apiKeys (string[]) – Array of API keys for Google Generative AI (at least one required).
  • options (optional object):
    • defaultMessage (string) – Default message if AI fails to generate a response.
    • model (string) – AI model to use (default: gemini-1.5-flash).
    • maxTokens (number) – Maximum token count in AI response (default: 50).
    • disableLogging (boolean) – Disable logging when set to true (default: false).

middleware()

Returns an Express middleware function that handles errors and provides AI-generated suggestions.

generateSmartResponse(errorMessage: string): Promise<string>

Manually generate an AI-powered response for a given error message.

Example:

const errorHandler = new AIErrorHandler(['your-api-key'])
const response = await errorHandler.generateSmartResponse('Invalid API token')
console.log(response)

Logging

By default, errors are logged using Winston. You can disable logging by setting disableLogging: true in options.

License

MIT

Author

Developed by David Patrick BugHunter.dev

Keywords

express

FAQs

Package last updated on 06 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts