Home > Backend Development > Golang > KrakenD sequential endpoint error response

KrakenD sequential endpoint error response

PHPz
Release: 2024-02-09 08:50:17
forward
590 people have browsed it

KrakenD 顺序端点错误响应

php editor Apple brings you an introduction to KrakenD sequential endpoint error response. KrakenD is a high-performance API gateway, but you may encounter some errors during use. Among them, sequential endpoint error response is a common problem. This article will explain in detail the causes and solutions of sequential endpoint error responses to help you better deal with this problem and improve the stability and performance of the API gateway.

Question content

krakend version: 2.2.1 go version: go1.19.3

I want to use krakend's sequential functionality to send sequential requests to two different endpoints.

Briefly summarize my case:

  • These two services can return success (200) and error (4**).
  • If the first service returns an error, I can see that error in Postman as a response. (This is what I want)
  • If the second service returns an error (4**) after the first service returns success (200), I will see a successful response from Postman while waiting to see the error returned by 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
      }
   }
 }
Copy after login

ide log

Postman Reply

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

Workaround

This is expected behavior of KrakenD.

When you make multiple calls, KrakenD will return whatever is available along with a 200 status code if at least one request succeeds. But in exchange, you get a header X-KrakenD-Complete: false telling you that something failed. You can read more about aggregation here p>

Since you are using a sequential proxy, when the first request fails, there is no need to do anything else as the next sequential call will automatically abort. So everything fails and KrakenD can't return anything, which is why you get the failure you want.

In the other case, KrakenD has something to return since the first call worked, and you receive partial data.

You should examine the contents of your client's X-KrakenD-Complete header to decide what to do

The above is the detailed content of KrakenD sequential endpoint error response. For more information, please follow other related articles on the PHP Chinese website!

source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template