302 Status code converted to 502 error response

I have a case where 302 response code is being converted to 502 Bad gateway in APIGEE X. I do not want to respond as an error for this scenario. 
The response received by the APIGEE X is shown below:

darpanjain420_0-1694588768696.png

 

Error message is :

{"fault":{"faultstring":"Unexpected EOF at target","detail":{"errorcode":"messaging.adaptors.http.flow.UnexpectedEOFAtTarget","reason":"TARGET_READ_UNEXPECTED_EOF"}}}

I just want to respond with 302 as it is with the response headers received as shown in above screenshot.

The current response being sent to the client is :

darpanjain420_1-1694588527698.png

Please help me here. Thanks in advance.
@dandino 

 

3 REPLIES 3

I think the Unexpected EOF is the more pertinent fact. Maybe the 302 being returned by your upstream is part of a incomplete or incorrect response. It seems that way - that is what the error message from Apigee is telling you. 

You can try it yourself - build a separate upstream that just returns 302 (correctly).  Apigee can proxy to that.  Build a passthrough proxy, invoke the proxy, the proxy will invoke the upstream. The upstream will send back a 302, Apigee will get  the 302 response, and will send that back to the client.  This works.  I just tried this on my own Apigee instance. It works just fine. (but I've done this before too). 

There is nothing you can do to Apigee to tell it to ignore the unexpected EOF.  The only way to correct this is to modify your target system so that it responds with a correct response.

 

Could you please give me the code you had tried here? As its difficult to follow the exact use case you have described.
The EOF is generated at the APIGEE end , because I dont see that EOF coming when I make the call directly to the target url

Could you please give me the code you had tried here?

it's just a passthrough proxy in Apigee, pointing to a simple target system that returns 302.  the code for the target system looks like this: 

const fs = require("fs"),
  app = require("express")(),
  morganLogging = require("morgan");

const port = process.env.PORT || 5950;

app.use(morganLogging("combined"));

app.get("/status-302", function (request, response) {
  const proto = request.headers["x-forwarded-proto"] || "https";
  response
    .header("Location", `${proto}://${request.headers.host}/ok`)
    .header("Content-Type", "application/json")
    .status(302)
    .send();
});

app.get("/ok", function (_request, response) {
  response
    .header("Content-Type", "application/json")
    .status(200)
    .send('{ "response": { "status" : "ok" } }\n');
});

// catchall
app.use(function (_request, response) {
  response.status(404).send("");
});

app.listen(port, function () {
  console.log("server listening on " + port);
});

I dont see that EOF coming when I make the call directly to the target url

ok. It could be that Apigee is simply more strict, when interacting with the target system, than the tool you are using to invoke it directly.

Have you tried the test I suggested ?  build a system that returns 302 (correctly). And proxy to it with Apigee. You'll see that a correct 302 is returned to the client. I think the upstream is not behaving as expected when sending the 302 response. Judging from the error Apigee is emitting, the upstream ends the response stream prematurely.