@zhaoworks/feh
TypeScript icon, indicating that this package has built-in type declarations

1.0.4 • Public • Published

feh feh npm version last commit

feh is a Fastify Error Responder, it's a plugin to facilitate and standardize error management in your Fastify application.

Usage

Installation

bun add @zhaoworks/feh
npm
npm install @zhaoworks/feh
yarn
yarn add @zhaoworks/feh
pnpm
pnpm add @zhaoworks/feh

Example

After adding Fastify and feh in your project, try this

import fastify from 'fastify';
import feh from '@zhaoworks/feh';

const server = fastify();

server.register(feh);

server.get('/', (_, reply) => {
  return reply.error(500, {
    message: 'something went completely wrong >:(',
  });
});

server
  .listen({ port: 4000 })
  .then(() => console.log('Listening on http://localhost:4000/'));

You can also add a custom format to your errors by registering a new error formatter.

server.register(feh, {
  format: (status, error) => ({ error: error.message, our_fault: status === 500 })
});

server.get('/', (_, reply) => {
  return reply.error(500, { message: 'a cat must have bitten the wires' }); // -> { error: 'a cat must have bitten the wires', our_fault: true }
});

Readme

Keywords

Package Sidebar

Install

npm i @zhaoworks/feh

Weekly Downloads

6

Version

1.0.4

License

MIT

Unpacked Size

4.42 kB

Total Files

5

Last publish

Collaborators

  • kauefraga
  • 7wf
  • zhaocode