@@ -103,6 +103,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
103
103
List <Region > unvisitedRegions = new ArrayList <>(allRegions );
104
104
105
105
int attempt = 0 ;
106
+ JsonMessage hubMessage = null ;
106
107
try (CloseableHttpClient client = newHttpClient ()) {
107
108
while (!allRegions .isEmpty ()) {
108
109
attempt ++;
@@ -116,7 +117,7 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
116
117
117
118
String target = route + request .getRequestURI ();
118
119
HttpResponse hubResponse = client .execute (post (target , message ));
119
- JsonMessage hubMessage = JsonMessageFactory .from (hubResponse .getEntity ().getContent ());
120
+ hubMessage = JsonMessageFactory .from (hubResponse .getEntity ().getContent ());
120
121
121
122
if (hubResponse .getStatusLine ().getStatusCode () == SC_OK ) {
122
123
String sessionId = hubMessage .getSessionId ();
@@ -150,15 +151,23 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
150
151
}
151
152
152
153
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
+ }
154
159
}
155
160
156
161
protected void replyWithOk (JsonMessage message , HttpServletResponse response ) throws IOException {
157
162
reply (SC_OK , message , response );
158
163
}
159
164
160
165
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 );
162
171
}
163
172
164
173
protected void reply (int code , JsonMessage message , HttpServletResponse response ) throws IOException {
0 commit comments