如何将Kong错误替换为自定义文本?
Kong错误
API率限制超过了。
如何将Kong错误替换为自定义文本,例如“ POC错误”?
Kong Error
API rate limit exceeded.
How Can I replace the Kong Error to a custom text for example "PoC Error"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该解决方案不是理想的选择,但就目前而言,直到出现更好的解决方案(也许来自Kong)之前。所有插件和内部插件都存在自定义错误消息的问题。
我已经创建了一个全局功能( nofollow noreferrer“> serverless-funtrions )检查状态代码是否高于400并拦截响应。
在函数“身体相”处理程序的顶部定义了一个带有所有截距误差的静态定义表。
问题在于,Kong错误并不总是看起来相同,因为它们通过从响应中查看“ content-type”标题来生成错误消息。
我的解决方案是将其与模板生成相同的UTIT( kong.utils ),并用不同的消息填充我的错误表。
首先,在功能后的“标头相”中,我检查响应代码。如果它高于400,我会清除“内容长度”标头(必需),并设置一个标志(例如Kong.ctx.custom_error),以表明需要拦截。
其次,在功能后的“身体相”中,我检查标志并与我生成的误差桌相匹配。如果发现匹配,则响应主体将被预定义的错误消息覆盖。
为了进行性能考虑,我通过将处理程序归还覆盖身体的处理程序来记住“身体相”的桌子。现在,Kong将在加载时生成一次表,如果出现请求,则仅调用返回的功能。
希望我能在某种程度上解释它,并有助于进一步
This solution is not ideal but for now it is working until a better solution (maybe from kong) comes up. The problem with custom error messages exists with all plugins and internals.
I have created a global post-function (serverless-functions) which checks if a status code is above 400 and intercepts the response.
A static defined table with all errors to intercept is defined at the top of the post-function "body-phase" handler.
The problem is that kong errors not always looks the same, because they generate the error message by looking at the "Content-Type" header from response.
My solution is to take the same util they took for template generation (kong.utils) and populate my error table with different messages.
First, in the post-function "header-phase", i check the response code. If it is above 400 i clear the "Content-Length" header (required) and set a flag (for example kong.ctx.custom_error) for next phase to indicate interception is required.
Second, in the post-function "body-phase", i check for the flag and match the response body against my generated error-table. If a match is found the response body will be overwritten with the predefined error message.
For performance considerations i memoized the table in the "body-phase" by returning the handler for overwriting the body to kong. For now kong will generate the table once on load and if a request occurs only the returned function will be invoked.
hope that I could explain it to some extent and it helps further