npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

catch-all-errors

v0.0.1

Published

Catch all JavaScript errors and post them to your server

Downloads

6

Readme

Tiny library to catch all JavaScript errors and email or post them to your server in 1.4k.

Enable it with a single line before other JavaScript:

<script src="https://chr15m.github.io/catch-all-errors/catch-all-errors.min.js" data-post-url="/api/errorhandler"></script>

No more mangled, half-understood, context-free error-feelings reported. \o/

npm i catch-all-errors

This is intended for self-hosting, small businesses, and indie-hacker scale traffic, not venture backed startup scale traffic.

API & usage

Catch every error and post to a URL on your server.

<script src="catch-all-errors.min.js" data-post-url="/api/errorhandler"></script>

By default only the first JS error is caught to prevent bad code from spamming of your API endpoint. You can change to continuous mode like this:

<script src="catch-all-errors.min.js" data-post-url="/api/errorhandler" data-continous></script>

By default the error is propagated through to default the browser resulting in console.errors but you can disable this behaviour with data-prevent-default:

<script src="catch-all-errors.min.js" data-post-url="/api/errorhandler" data-prevent-default></script>

Show error email modal

Screenshot of the modal

Use data-email-to to put up a simple modal which will allow the user to email the results to a developer.

<script src="catch-all-errors.min.js" data-email-to='[email protected]'>

The way this mode works is to generate a mailto: link with the traceback details. When the user clicks "Send" it will open their mail program with a pre-written email to the address nominated.

Catch all errors in a callback function

Use your own callback function to handle the caught errors. The data-callback parameter should specify the name of the callback function which is passed one parameter with the error properties.

<script src="catch-all-errors.min.js" data-callback="catcher"></script>.

Error object properties

Errors will have the following properties when caught and handled:

{
  "message": "blee is not defined",
  "url": "http://localhost:8000/",
  "line": 23,
  "column": 9,
  "useragent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:66.0) Gecko/20100101 Firefox/66.0",
  "stack": "window.onload@http://localhost:8000/:23:9\n",
}

Where line and column are the position in the file where the error occured, and stack is the stack-trace leading up to the error.

Example server API

example-api.php provides a simple example of printing the JS errors into the error log using PHP.

Why use this instead of hosted service X?

  • You like self-hosting stuff.
  • You don't want to sign up for yet another service.
  • You don't need all of their weird complicated features.
  • Those services keep going out of business.
  • You find those services to be over-engineered.

This won't ever become complicated bloatware requiring a signup.