@written/throwables
TypeScript icon, indicating that this package has built-in type declarations

2.0.4 • Public • Published

Written Logo

@written/throwables

Make Appwrite Error Handling simpler. Inspired heavily by Svelte Errors

Codeberg License

Installation

In your function, run:

pnpm i @written/throwables

Usage

import throwables, {
  clientException,
  serverException,
  redirect,
} from '@written/throwables';

const app = new App().use(throwables()); // use the throwables middleware

app.get('/err', ({ req, res }) => {
  throw clientException(400, 'this is an error endpoint');
});

app.get('/fuckup', ({ req, res }) => {
  throw serverException(500, 'whoops, we fucked up!'); // this will log the stack while we're at it in the default handler
});

app.get('/redirect', ({ req, res }) => {
  throw redirect('https://example.com/', 302); // redirect with http 302; if you omit the code, we use 307.
});

export default app.server();

For both clientException and serverException, the resulting response's body has the shape {success:false,error:<reason>}, where reason defaults to No message specified

/@written/throwables/

    Package Sidebar

    Install

    npm i @written/throwables

    Weekly Downloads

    3

    Version

    2.0.4

    License

    MIT

    Unpacked Size

    31.6 kB

    Total Files

    12

    Last publish

    Collaborators

    • exponentialworkload