1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/examples/with-sentry/pages/_app.js
Adam Stankiewicz cd1d3640a9 Improve with-sentry example (#5727)
* Improve with-sentry example

* remove nonexisting keys from request and update errorInfo handling

* readd query and pathname

* read query and params and add pathname and query to client
2018-12-10 23:59:12 +01:00

33 lines
793 B
JavaScript

import App from 'next/app'
import { captureException } from '../utils/sentry'
class MyApp extends App {
// This reports errors before rendering, when fetching initial props
static async getInitialProps (appContext) {
const { Component, ctx } = appContext
let pageProps = {}
try {
if (Component.getInitialProps) {
pageProps = await Component.getInitialProps(ctx)
}
} catch (e) {
captureException(e, ctx)
throw e // you can also skip re-throwing and set property on pageProps
}
return {
pageProps
}
}
// This reports errors thrown while rendering components
componentDidCatch (error, errorInfo) {
captureException(error, { errorInfo })
super.componentDidCatch(error, errorInfo)
}
}
export default MyApp