1. ouch
Javascript error handling for cool kids
ouch
Package: ouch
Created by: quorrajs
Last modified: Sun, 05 Mar 2023 20:40:08 GMT
Version: 2.0.1
License: MIT
Downloads: 105,721
Repository: https://github.com/quorrajs/Ouch

Install

npm install ouch
yarn add ouch

Ouch

NodeJS errors for cool kids

npm version
Build Status
Quality
Documentation Status


Ouch!

Ouch is a NodeJS implementation of PHP's Whoops library. It's not an exact port of
Whoops, but implements similar functionality and uses same front end resources in some of its error handlers. It is an
error handler base/framework for NodeJs. Out-of-the-box, it provides a pretty error interface that helps you debug your
web projects, but at heart it's a simple yet powerful stacked error handling system.

Pretty page handler demo

Blue theme

Orange theme

Installation

The source is available for download from GitHub. Alternatively, you
can install using Node Package Manager (npm):

 npm install ouch

Usage examples

     // With PrettyPageHandler
    http.createServer(function nsjfkj(req, res){

        if (req.url === '/favicon.ico') {
            res.writeHead(200, {'Content-Type': 'image/x-icon'} );
            res.end();
            return;
        }

        var d = domain.create();

        d.on('error', function(e){
            var ouchInstance = (new Ouch).pushHandler(
                    new Ouch.handlers.PrettyPageHandler('orange', null, 'sublime')
                );
            ouchInstance.handleException(e, req, res, function (output) {
                console.log('Error handled properly')
            });
        });
        d.run(function(){

            // your application code goes here

        });

    }).listen('1338', 'localhost');


    // With custom callback
    var ouchInstance = (new Ouch).pushHandler(
        function(next, exception, inspector, run, request, response){

            // custom handler logic

            next();
        });

    ouchInstance.handleException(e, req, res, function (output) {
        console.log('Error handled properly')
    });

For more options, have a look at the example files in examples to get a feel for how things work. Also take a look at the API Documentation and the list of available handlers below.

Available Handlers

Ouch currently ships with the following built-in handlers, available in the require("ouch").handlers namespace:

  • PrettyPageHandler - Shows a pretty error page when something goes pants-up
  • JsonResponseHandler - Process errors and returns information on them as a JSON string.
  • CallbackHandler - Wraps a callable as a handler. You do not need to use this handler explicitly, Ouch will automatically wrap any callable you pass to ouchInstance.pushHandler.

Todo

- Add more handlers.

License

Ouch is open-sourced software licensed under the MIT license.

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin