@@ -103,6 +103,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
103103 List <Region > unvisitedRegions = new ArrayList <>(allRegions );
104104
105105 int attempt = 0 ;
106+ JsonMessage hubMessage = null ;
106107 try (CloseableHttpClient client = newHttpClient ()) {
107108 while (!allRegions .isEmpty ()) {
108109 attempt ++;
@@ -116,7 +117,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
116117
117118 String target = route + request .getRequestURI ();
118119 HttpResponse hubResponse = client .execute (post (target , message ));
119- JsonMessage hubMessage = JsonMessageFactory .from (hubResponse .getEntity ().getContent ());
120+ hubMessage = JsonMessageFactory .from (hubResponse .getEntity ().getContent ());
120121
121122 if (hubResponse .getStatusLine ().getStatusCode () == SC_OK ) {
122123 String sessionId = hubMessage .getSessionId ();
@@ -150,15 +151,23 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
150151 }
151152
152153 LOGGER .error ("[SESSION_NOT_CREATED] [{}] [{}] [{}]" , user , remoteHost , browser );
153- replyWithError ("Cannot create session on any available node" , response );
154+ if (hubMessage == null ) {
155+ replyWithError ("Cannot create session on any available node" , response );
156+ } else {
157+ replyWithError (hubMessage , response );
158+ }
154159 }
155160
156161 protected void replyWithOk (JsonMessage message , HttpServletResponse response ) throws IOException {
157162 reply (SC_OK , message , response );
158163 }
159164
160165 protected void replyWithError (String errorMessage , HttpServletResponse response ) throws IOException {
161- reply (SC_INTERNAL_SERVER_ERROR , JsonMessageFactory .error (13 , errorMessage ), response );
166+ replyWithError (JsonMessageFactory .error (13 , errorMessage ), response );
167+ }
168+
169+ protected void replyWithError (JsonMessage message , HttpServletResponse response ) throws IOException {
170+ reply (SC_INTERNAL_SERVER_ERROR , message , response );
162171 }
163172
164173 protected void reply (int code , JsonMessage message , HttpServletResponse response ) throws IOException {
0 commit comments