Skip to content

Commit

Permalink
chore(controller): return 502 instead of 500 when online eval service…
Browse files Browse the repository at this point in the history
… is unavailable (#1681)
  • Loading branch information
jialeicui authored Dec 29, 2022
1 parent 56b04b3 commit 09431a2
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
Expand All @@ -32,6 +33,7 @@
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.utils.URIUtils;
import org.apache.http.conn.HttpHostConnectException;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicHttpEntityEnclosingRequest;
Expand Down Expand Up @@ -70,8 +72,13 @@ public void service(HttpServletRequest req, HttpServletResponse res) throws Serv
path = path + "?" + req.getQueryString();
}
var request = generateRequest(req, path);
var response = httpClient.execute(host, request);
generateResponse(response, res);
try {
var response = httpClient.execute(host, request);
generateResponse(response, res);
} catch (UnknownHostException | HttpHostConnectException e) {
// return 502 if host or port is unavailable
res.setStatus(HttpServletResponse.SC_BAD_GATEWAY);
}
}

protected HttpRequest generateRequest(HttpServletRequest req, String uri) throws IOException {
Expand Down

0 comments on commit 09431a2

Please sign in to comment.