# ouch

> Javascript error handling for cool kids

Latest version **2.0.1** (published 2022-05-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install ouch
pnpm add ouch
yarn add ouch
bun add ouch
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2022-05-13 |
| First published | 2015-03-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4.0.0 |
| Dependencies | 4 |
| Unpacked size | 119.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 196 |
| Author | Harish Anchu |
| Maintainers | harishanchu |
| Keywords | error, handler, exception, pretty, ouch, beautify, whoops |

## Links

- npm: https://www.npmjs.com/package/ouch
- Repository: https://github.com/quorrajs/Ouch
- Homepage: https://github.com/quorrajs/Ouch#readme
- Issues: https://github.com/quorrajs/Ouch/issues
- npm.io page: https://npm.io/package/ouch

## Dependencies (4)

- [ejs](https://npm.io/package/ejs.md) ^3.1.7
- [lodash](https://npm.io/package/lodash.md) ^4.17.10
- [escape-html](https://npm.io/package/escape-html.md) ^1.0.1
- [@positron/stack-trace](https://npm.io/package/@positron/stack-trace.md) 1.0.0

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 2.0.1 (latest) — 2022-05-13
- 2.0.0 — 2018-09-16
- 1.1.0 — 2017-11-19
- 1.0.0 — 2016-06-10
- 0.2.0-beta — 2015-03-20
- 0.1.0-alpha-1 — 2015-03-17
- 0.1.0-alpha — 2015-03-14
- 0.0.1-alpha.2 — 2015-03-13
- 0.0.1-alpha — 2015-03-13
- 0.0.0-init — 2015-03-12

## README

Ouch
====

NodeJS errors for cool kids

[![npm version](https://badge.fury.io/js/ouch.svg)](http://badge.fury.io/js/ouch)
[![Build Status](https://travis-ci.org/quorrajs/Ouch.svg?branch=master)](https://travis-ci.org/quorrajs/Ouch)
[![Quality](https://codeclimate.com/github/quorrajs/Ouch/badges/gpa.svg)](https://codeclimate.com/github/quorrajs/Ouch)
[![Documentation Status](https://readthedocs.org/projects/ouch/badge/?version=latest)](https://readthedocs.org/projects/ouch/?badge=latest)

-----

![Ouch!](http://i.imgur.com/EPXL1Zq.png)

**Ouch** is a NodeJS implementation of PHP's [Whoops](https://github.com/filp/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](https://quorrajs.github.io/Ouch/demo/)

[Orange theme](https://quorrajs.github.io/Ouch/demo/orange.html)

## Installation

The source is available for download from [GitHub](https://github.com/quorrajs/Ouch). Alternatively, you
can install using Node Package Manager (npm):

```javascript
npm install ouch
```

## Usage examples

``` javascript
    // 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](http://ouch.readthedocs.org/en/latest/api-docs/) 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`](https://github.com/quorrajs/Ouch/blob/master/handler/PrettyPageHandler.js) - Shows a pretty error page when something goes pants-up
- [`JsonResponseHandler`](https://github.com/quorrajs/Ouch/blob/master/handler/JsonResponseHandler.js) - Process errors and returns information on them as a JSON string.
- [`CallbackHandler`](https://github.com/quorrajs/Ouch/blob/master/handler/CallbackHandler.js) - 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](http://opensource.org/licenses/MIT).

---
_Source: https://npm.io/package/ouch · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
