如何解决“ API”解决而不发送响应获取”。使用哨兵时
我已经查看了无数其他帖子,找不到答案,为什么我在不发送/api/git/festment-commit的响应的情况下连续解决api,这可能会导致停滞的请求。 Next.js中的错误?一旦我禁用哨兵,它就消失了,还有其他人为此而苦苦挣扎?
import type { NextApiRequest, NextApiResponse } from 'next'
import { withSentry } from "@sentry/nextjs";
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const response = await fetch(`https://api.github.com/repos/####/####/commits?per_page=1`, {
method: 'GET'
});
const data = await response.json();
const commit = data[0]
res.status(200).json({
sha: {
full: commit.sha,
short: commit.sha.substring(0,7)
},
committer: commit.commit.committer.name,
time: commit.commit.committer.date,
html_url: commit.html_url
})
};
export default withSentry(handler);
I've looked at countless other posts and cannot find the answer to this, why am I continuously getting the API resolved without sending a response for /api/git/latest-commit, this may result in stalled requests.
error in next.js? As soon as I disable sentry it goes away, has anyone else struggled with this?
import type { NextApiRequest, NextApiResponse } from 'next'
import { withSentry } from "@sentry/nextjs";
const handler = async (req: NextApiRequest, res: NextApiResponse) => {
const response = await fetch(`https://api.github.com/repos/####/####/commits?per_page=1`, {
method: 'GET'
});
const data = await response.json();
const commit = data[0]
res.status(200).json({
sha: {
full: commit.sha,
short: commit.sha.substring(0,7)
},
committer: commit.commit.committer.name,
time: commit.commit.committer.date,
html_url: commit.html_url
})
};
export default withSentry(handler);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
运行代码在我的结尾上产生以下消息(
下一个12.1.4
,@sentry/nextjs 6.19.7
):为了抑制Sentry的警告,我将此环境变量添加到
.env.development
文件:为了抑制Next.js API路由的警告,我将其添加到
最新限制中。 TS
:两个警告不再出现,数据似乎正确返回。
经过一番挖掘,这就是他们对正在发生的事情的解释:
https://github.com/getsentry/sentry-javascript/pull/pull/pull/pull/4139
Running your code produced the following message on my end (
next 12.1.4
,@sentry/nextjs 6.19.7
):To suppress the warning from Sentry, I added this environment variable to an
.env.development
file:To suppress the warning from the Next.js API route, I added this to
latest-commit.ts
:Both warnings no longer appear and the data appears to return correctly.
After some digging, this was their explanation as to what's happening:
https://github.com/getsentry/sentry-javascript/pull/4139