KrakenD顺序端点错误响应

huangapple go评论73阅读模式
英文:

KrakenD sequential endpoint wrong response

问题

krakenD版本:2.2.1
go版本:go1.19.3

我想使用krakenD的顺序功能向两个不同的端点发送顺序请求。

简要总结我的情况:

  • 这两个服务可以返回成功(200)和错误(4xx)。
  • 如果第一个服务返回错误,我可以在Postman中看到错误作为响应。(这是我想要的情况)
  • 如果第二个服务在第一个服务返回成功(200)后返回错误(4xx),我会在等待第二个服务返回的错误时看到来自Postman的成功响应。

顺序端点示例:

{
   "endpoint": "/companies/validate",
   "method": "GET",
   {{ include "input_headers.txt" }},
   "backend": [
    {
      "host": ["{{ .service.credential_service_url }}"],
      "url_pattern": "/tokens/validate",
      "method": "GET",
      "extra_config": {
         "backend/http": {
            "return_error_code": true
         }
      }
    },
    {
      "host": ["{{ .service.company_service_url }}"],
      "url_pattern": "/companies/{resp0_companyId}/validate",
      "method": "GET",
      "extra_config": {
         "backend/http": {
            "return_error_code": true
         }
      }
    }
   ],
   "extra_config": {
      "proxy": {
         "sequential": true
      }
   }
 }

IDE日志

Postman响应

正如你所看到的,第一个服务正常工作,第二个服务返回错误,但Postman响应返回成功。

英文:

krakenD version: 2.2.1
go version: go1.19.3

I want to send sequential requests to two different endpoints using krakenD's sequential feature.

To summarize my case briefly:

  • These two services can return both success (200) and error (4**).
  • If the first service returns an error, I can see the error in postman as a response. (this is a situation I want)
  • If the second service returns an error (4**) after the first service returns success (200), I see the success response from postman while waiting to see the error returned from the second service.

sequential endpoint example:

{
   "endpoint": "/companies/validate",
   "method": "GET",
   {{ include "input_headers.txt" }},
   "backend": [
    {
      "host": ["{{ .service.credential_service_url }}"],
      "url_pattern": "/tokens/validate",
      "method": "GET",
      "extra_config": {
         "backend/http": {
            "return_error_code": true
         }
      }
    },
    {
      "host": ["{{ .service.company_service_url }}"],
      "url_pattern": "/companies/{resp0_companyId}/validate",
      "method": "GET",
      "extra_config": {
         "backend/http": {
            "return_error_code": true
         }
      }
    }
   ],
   "extra_config": {
      "proxy": {
         "sequential": true
      }
   }
 }

ide logs

postman response

As you can see, the first service works correctly, the second service returns an error, but the postman response returns a success.

答案1

得分: 1

这是KrakenD的预期行为。

当你进行多个调用时,如果至少有一个请求成功,KrakenD将返回任何可用的内容,并带有200状态码。但是作为交换,你会收到一个头部X-KrakenD-Complete: false,告诉你有些东西失败了。你可以在这里阅读更多关于聚合的信息

由于你正在使用顺序代理,当第一个请求失败时,没有其他事情可做,因为下一个顺序调用会自动中止。因此,所有内容都失败了,KrakenD无法返回任何内容,这就是为什么你得到了期望的失败结果。

另一种情况是,因为第一个调用成功了,KrakenD有东西可以返回,你会收到部分数据。

你应该在客户端检查X-KrakenD-Complete头部的内容,以决定接下来该做什么。

英文:

This is the expected behavior of KrakenD.

When you do more than one call, if at least one of the requests succeed, KrakenD will return any available content together with a 200 status code. But in exchange, you receive a header X-KrakenD-Complete: false telling you that something failed. You can read more about aggregation here

As you are using the sequential proxy, when the first request fails, there is nothing else to do as the next sequential call is automatically aborted. In consequence, ALL content failed and KrakenD cannot return anything, and this is why you get the desired failure.

On the other case, because the first call works, KrakenD has something to return, and you receive partial data.

You should check in your client de content of the X-KrakenD-Complete header to decide what to do

huangapple
  • 本文由 发表于 2023年3月22日 19:38:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/75811790.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定