Skip to content

How to use tiny-http with Sentry for error monitoring? #384

Closed Answered by aarontravass
keinsell asked this question in Q&A
Discussion options

You must be logged in to vote

Initiate Sentry in your root file.

Then, create a middlware that can be passed to the onError handler

import { captureException } from '@sentry/node';
import { App } from '@tinyhttp/app';

const errorHandler = (error, req, res) => {
    captureException(error);
    return res.send("Server error!")
}

const app = new App({ onError: errorHandler });

app.get('/user', (req, res) => {
    throw Error('error!');;
})

app.listen(3000, () => { console.log("listening!") })

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@keinsell
Comment options

@aarontravass
Comment options

Answer selected by talentlessguy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants