Skip to content

cengizilhan/js-global-error-handler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JS Global Error Handler SDK

A professional-grade, lightweight JavaScript library for capturing and reporting client-side errors.

https://www.npmjs.com/package/js-global-error-handler

Features

  • Multi-Source Capture: Catch errors from window.onerror, Promise rejections, Fetch/XHR failures, and manual console.error calls.
  • Normalization: Automatically formats various error types into a consistent JSON payload.
  • Fingerprinting: Built-in deduplication to prevent flooding your servers with the same error.
  • Aggressive Tracking: Monkey-patches core APIs in development/QA environments for deep visibility.
  • Zero Dependencies: Lightweight and vanilla JavaScript.

Getting Started

Installation

npm install js-global-error-handler

Usage

Option 1: NPM (React, Vue, Angular, etc.)

import { init } from 'js-global-error-handler';

// Initialize at the very top of your app
init({
  endpoint: 'https://api.yourdomain.com/errors',
  method: 'POST', 
  env: 'production',
  reportingEnabled: true
});

Option 2: CDN / Script Tag (Legacy, Vanilla JS)

<!-- Load the library -->
<script src="https://cdn.jsdelivr.net/npm/js-global-error-handler/dist/tracker.umd.js"></script>

<script>
  ErrorTracker.init({
    endpoint: 'https://api.yourdomain.com/errors',
    method: 'POST',
    env: 'production'
  });
</script>

Configuration Options

Pass these options to the init() function:

Option Type Default Description
endpoint string '/api/error/add' API URL where errors will be sent.
method string 'POST' HTTP method (POST, PUT, GET).
env string 'development' Environment mode. production enables sending reports.
reportingEnabled boolean false Master switch to enable/disable network reporting.
maxSameError number 5 Prevents flooding by limiting duplicate error reports.
aggressiveTracking boolean true Monkey-patches console.error, fetch, and XMLHttpRequest for deeper visibility.

Development commands

  • npm run dev: Start development server with demo dashboard.
  • npm run build: Build the library and demo files for production.

Directory Structure

  • src/js/tracker.js: Main entry point.
  • src/js/utils.js: Error normalization and logic.
  • src/js/transports.js: Network transmission.
  • src/js/config.js: Centralized settings.

License

MIT

About

js global error handler

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published