# ns-error

> Server error

Latest version **1.0.0** (published 2018-02-23) · ISC license · 0 weekly downloads

## Install

```sh
npm install ns-error
pnpm add ns-error
yarn add ns-error
bun add ns-error
```

## 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 | 1.0.0 |
| Published | 2018-02-23 |
| First published | 2018-02-23 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Jeremy Moore |
| Maintainers | jeremy.moore |

## Links

- npm: https://www.npmjs.com/package/ns-error
- Repository: https://github.com/jeremy-moore/ns-error
- Homepage: https://github.com/jeremy-moore/ns-error#readme
- Issues: https://github.com/jeremy-moore/ns-error/issues
- npm.io page: https://npm.io/package/ns-error

## Dependencies (1)

- [verror](https://npm.io/package/verror.md) ^1.10.0

## Recent versions

- 1.0.0 (latest) — 2018-02-23

## README

## NS Error

Module for ServerError, error names, status codes and helper functions.

```
    const {ERRORS, STATUS, sanitise, ServerError} = require('ns-error')
    
    describe('ServerError', () => {

        it('should construct minimal server error', () => {
            const se = new ServerError(ERRORS.SERVER, STATUS._500_InternalServerError)
            expect(se.name).toBe(ERRORS.SERVER)
            expect(se.status).toBe(STATUS._500_InternalServerError)
            expect(se.message).toBe('')
            expect(se.cause).toBeNull()
            expect(se.details).toBeNull()
            expect(sanitise(se)).toEqual({'error': {'name': 'ServerError'}})
        })

        it('should construct maximal server error', () => {
            const cause = new Error('Catastrophe')
            const message = 'A catastrophe error occurred!'
            const details = 'I just pressed this red button and ... poof'
            const options = {message, details, cause}
            const se = new ServerError(ERRORS.SERVER, STATUS._500_InternalServerError, options)
            expect(se.name).toBe(ERRORS.SERVER)
            expect(se.status).toBe(STATUS._500_InternalServerError)
            expect(se.message).toBe('A catastrophe error occurred!: Catastrophe')
            expect(se.cause).toBe(cause)
            expect(se.details).toBe(details)
            expect(sanitise(se)).toEqual({
                error: {
                    name: ERRORS.SERVER,
                    message: message + ': ' + cause.message,
                    details
                }
            })
            expect(sanitise(se)).toEqual({
                error: {
                    name: 'ServerError',
                    message: 'A catastrophe error occurred!: Catastrophe',
                    details: 'I just pressed this red button and ... poof'
                }
            })
        })
    })

```

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