@flares/express

TODO

Usage no npm install needed!

<script type="module">
  import flaresExpress from 'https://cdn.skypack.dev/@flares/express';
</script>

README

@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)