Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
CoCo_Code_Op2
next.js
提交
b9c71d37
N
next.js
项目概览
CoCo_Code_Op2
/
next.js
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
next.js
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
b9c71d37
编写于
11月 06, 2019
作者:
J
JJ Kasper
提交者:
Joe Haddad
11月 06, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Revert experimental plugins code from sentry example (#9317)
上级
0022633d
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
110 addition
and
6 deletion
+110
-6
examples/with-sentry-simple/next.config.js
examples/with-sentry-simple/next.config.js
+20
-5
examples/with-sentry-simple/package.json
examples/with-sentry-simple/package.json
+2
-1
examples/with-sentry-simple/pages/_app.js
examples/with-sentry-simple/pages/_app.js
+22
-0
examples/with-sentry-simple/pages/_error.js
examples/with-sentry-simple/pages/_error.js
+66
-0
未找到文件。
examples/with-sentry-simple/next.config.js
浏览文件 @
b9c71d37
const
withSourceMaps
=
require
(
'
@zeit/next-source-maps
'
)()
module
.
exports
=
withSourceMaps
({
env
:
{
SENTRY_DSN
:
'
hello-world
'
,
// would want to synchronously grab git commit id here for
// best debugging experience
SENTRY_RELEASE
:
'
0.0.1
'
webpack
:
(
config
,
options
)
=>
{
// In `pages/_app.js`, Sentry is imported from @sentry/node. While
// @sentry/browser will run in a Node.js environment, @sentry/node will use
// Node.js-only APIs to catch even more unhandled exceptions.
//
// This works well when Next.js is SSRing your page on a server with
// Node.js, but it is not what we want when your client-side bundle is being
// executed by a browser.
//
// Luckily, Next.js will call this webpack function twice, once for the
// server and once for the client. Read more:
// https://nextjs.org/docs#customizing-webpack-config
//
// So ask Webpack to replace @sentry/node imports with @sentry/browser when
// building the browser's bundle
if
(
!
options
.
isServer
)
{
config
.
resolve
.
alias
[
'
@sentry/node
'
]
=
'
@sentry/browser
'
}
return
config
}
})
examples/with-sentry-simple/package.json
浏览文件 @
b9c71d37
...
...
@@ -8,7 +8,8 @@
"start"
:
"next start"
},
"dependencies"
:
{
"@next/plugin-sentry"
:
"latest"
,
"@sentry/browser"
:
"^5.1.0"
,
"@sentry/node"
:
"^5.6.2"
,
"next"
:
"latest"
,
"react"
:
"^16.8.6"
,
"react-dom"
:
"^16.8.6"
...
...
examples/with-sentry-simple/pages/_app.js
0 → 100644
浏览文件 @
b9c71d37
import
React
from
'
react
'
import
App
from
'
next/app
'
import
*
as
Sentry
from
'
@sentry/node
'
Sentry
.
init
({
// Replace with your project's Sentry DSN
dsn
:
'
https://00000000000000000000000000000000@sentry.io/1111111
'
})
class
MyApp
extends
App
{
render
()
{
const
{
Component
,
pageProps
}
=
this
.
props
// Workaround for https://github.com/zeit/next.js/issues/8592
const
{
err
}
=
this
.
props
const
modifiedPageProps
=
{
...
pageProps
,
err
}
return
<
Component
{...
modifiedPageProps
}
/
>
}
}
export
default
MyApp
examples/with-sentry-simple/pages/_error.js
0 → 100644
浏览文件 @
b9c71d37
import
React
from
'
react
'
import
Error
from
'
next/error
'
import
*
as
Sentry
from
'
@sentry/node
'
const
MyError
=
({
statusCode
,
hasGetInitialPropsRun
,
err
})
=>
{
if
(
!
hasGetInitialPropsRun
&&
err
)
{
// getInitialProps is not called in case of
// https://github.com/zeit/next.js/issues/8592. As a workaround, we pass
// err via _app.js so it can be captured
Sentry
.
captureException
(
err
)
}
return
<
Error
statusCode
=
{
statusCode
}
/
>
}
MyError
.
getInitialProps
=
async
({
res
,
err
,
asPath
})
=>
{
const
errorInitialProps
=
await
Error
.
getInitialProps
({
res
,
err
})
// Workaround for https://github.com/zeit/next.js/issues/8592, mark when
// getInitialProps has run
errorInitialProps
.
hasGetInitialPropsRun
=
true
if
(
res
)
{
// Running on the server, the response object is available.
//
// Next.js will pass an err on the server if a page's `getInitialProps`
// threw or returned a Promise that rejected
if
(
res
.
statusCode
===
404
)
{
// Opinionated: do not record an exception in Sentry for 404
return
{
statusCode
:
404
}
}
if
(
err
)
{
Sentry
.
captureException
(
err
)
return
errorInitialProps
}
}
else
{
// Running on the client (browser).
//
// Next.js will provide an err if:
//
// - a page's `getInitialProps` threw or returned a Promise that rejected
// - an exception was thrown somewhere in the React lifecycle (render,
// componentDidMount, etc) that was caught by Next.js's React Error
// Boundary. Read more about what types of exceptions are caught by Error
// Boundaries: https://reactjs.org/docs/error-boundaries.html
if
(
err
)
{
Sentry
.
captureException
(
err
)
return
errorInitialProps
}
}
// If this point is reached, getInitialProps was called without any
// information about what the error might be. This is unexpected and may
// indicate a bug introduced in Next.js, so record it in Sentry
Sentry
.
captureException
(
new
Error
(
`_error.js getInitialProps missing data at path:
${
asPath
}
`
)
)
return
errorInitialProps
}
export
default
MyError
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录