NextJS errorMessage:“响应有效负载大小超出了允许的最大有效负载大小(6291556 字节)”

发布于 2025-01-11 12:40:28 字数 265 浏览 0 评论 0原文

看来我的 API 请求有效负载的响应在大小方面很大,每当我访问呈现此响应的页面时,我

{
"errorMessage": "Response payload size exceeded maximum allowed payload size (6291556 bytes).",
"errorType": "Function.ResponseSizeTooLarge"
}

都会收到此消息如何操作此响应以避免我的 NextJS 应用程序上出现此错误?

It seems the response from my API request payload is much in terms of size, whenever I visit the page where this response is rendered, I get this message

{
"errorMessage": "Response payload size exceeded maximum allowed payload size (6291556 bytes).",
"errorType": "Function.ResponseSizeTooLarge"
}

How am I supposed to manipulate this response to avoid this error on my NextJS application?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

踏雪无痕 2025-01-18 12:40:28

此问题分为两个部分,

1. 如何处理显示错误

如果您控制 API

检查响应长度并发送适当的标头 - 请参阅 https://stackoverflow.com/a/61504772/13749957

如果您无法控制API 的

这只是您的应用程序处理错误并查找 errorType 并通知用户 - 如果您有一种机制来获取汇总或后备 API,请使用它。

2. 如果您控制 API,请压缩或操纵响应。

  1. 如果响应负载是二进制的 - 比如说资产,您可以在发送之前查看压缩,或者通过像 cloudinary 这样的转码器来获得更小的响应。

  2. 如果响应负载可以进行 gzip 压缩但尚未进行,请在发送之前对其进行 gzip 压缩。

本文讨论如何在 api 的 https 上运行 gzip ://techblog.commercetools.com/gzip-on-aws-lambda-and-api-gateway-5170bb02b543

There are two parts to this issue,

1. How do you handle the error from showing up

If you are in control of the API

Check for the response length and send appropriate headers - see https://stackoverflow.com/a/61504772/13749957

If you are not in control of the API

This is just your application handling the error and looking for the errorType and informing the user - If you have a mechanism to get a summarized or a fallback api use that.

2. If you are in control of the API, compressing or manipulating the response.

  1. If the response payload is binary - say an asset, you could look at compression before sending or via a transcoder like cloudinary to get a smaller response.

  2. If the response payload can be gzipped and isn't already, gzip it before sending.

This article discusses how to get a gzip going on api's https://techblog.commercetools.com/gzip-on-aws-lambda-and-api-gateway-5170bb02b543

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文