@flares/express
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-beta.32 • Public • Published

@flares/express

This package is intended to use with packages that are compatible with @flares/core like:

Basic Usage

import express from 'express'
import { FlareErrorRequestHandler, ThrowErrorRequestHandler } from '@flare/express'

// You can use any cased package to meet your code style in project
import { NotFound404, Internal500, Fls } from '@flares/pascal-case-code-flares'

const app = express()

app.get('/not-found', ThrowErrorRequestHandler(NotFound404()))

app.get('/forbidden', (req, res, next) => {
    throw Fls.Forbidden403('My message')
})

app.get('/forbidden', (req, res, next) => {
    try {
        throw new Error('Cause')
    } catch (e) {
        throw new Internal500('My custom message', e, { timestamp: Date.now() })
    }
})

app.get('/wrap-non-flare', () => {
    throw new Error('Not flare error')
})

app.use(FlareErrorRequestHandler({
    onServerFlare: console.error,
    wrapNonFlare: Internal500
}))


app.listen(8000)

Package Sidebar

Install

npm i @flares/express

Weekly Downloads

5

Version

1.0.0-beta.32

License

MIT

Unpacked Size

14.1 kB

Total Files

12

Last publish

Collaborators

  • vaderkos