@written/throwables
v2.0.4
Published
Make Appwrite Error Handling simpler
Downloads
9
Readme
@written/throwables
Make Appwrite Error Handling simpler. Inspired heavily by Svelte Errors
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