Handle when server doesn't send the expected response
This commit is contained in:
@@ -33,6 +33,7 @@ import java.util.concurrent.BlockingQueue;
|
|||||||
import com.sheepit.client.Error.ServerCode;
|
import com.sheepit.client.Error.ServerCode;
|
||||||
import com.sheepit.client.Error.Type;
|
import com.sheepit.client.Error.Type;
|
||||||
import com.sheepit.client.exception.FermeException;
|
import com.sheepit.client.exception.FermeException;
|
||||||
|
import com.sheepit.client.exception.FermeExceptionBadResponseFromServer;
|
||||||
import com.sheepit.client.exception.FermeExceptionNoRightToRender;
|
import com.sheepit.client.exception.FermeExceptionNoRightToRender;
|
||||||
import com.sheepit.client.exception.FermeExceptionNoSession;
|
import com.sheepit.client.exception.FermeExceptionNoSession;
|
||||||
import com.sheepit.client.exception.FermeExceptionNoSpaceLeftOnDevice;
|
import com.sheepit.client.exception.FermeExceptionNoSpaceLeftOnDevice;
|
||||||
@@ -247,6 +248,18 @@ public class Client {
|
|||||||
}
|
}
|
||||||
continue; // go back to ask job
|
continue; // go back to ask job
|
||||||
}
|
}
|
||||||
|
catch (FermeExceptionBadResponseFromServer e) {
|
||||||
|
int wait = 15;
|
||||||
|
int time_sleep = 1000 * 60 * wait;
|
||||||
|
this.gui.status(String.format("Bad answer from server. Will retry in %s minutes", wait));
|
||||||
|
try {
|
||||||
|
Thread.sleep(time_sleep);
|
||||||
|
}
|
||||||
|
catch (InterruptedException e1) {
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
continue; // go back to ask job
|
||||||
|
}
|
||||||
catch (FermeException e) {
|
catch (FermeException e) {
|
||||||
this.gui.error("Client::renderingManagement exception requestJob (1) " + e.getMessage());
|
this.gui.error("Client::renderingManagement exception requestJob (1) " + e.getMessage());
|
||||||
StringWriter sw = new StringWriter();
|
StringWriter sw = new StringWriter();
|
||||||
|
|||||||
@@ -46,7 +46,9 @@ public class Error {
|
|||||||
CPU_NOT_SUPPORTED(18),
|
CPU_NOT_SUPPORTED(18),
|
||||||
GPU_NOT_SUPPORTED(19),
|
GPU_NOT_SUPPORTED(19),
|
||||||
|
|
||||||
|
// internal error handling
|
||||||
NO_SPACE_LEFT_ON_DEVICE(100),
|
NO_SPACE_LEFT_ON_DEVICE(100),
|
||||||
|
ERROR_BAD_RESPONSE(101),
|
||||||
;
|
;
|
||||||
|
|
||||||
private final int id;
|
private final int id;
|
||||||
@@ -89,6 +91,7 @@ public class Error {
|
|||||||
|
|
||||||
// internal error handling
|
// internal error handling
|
||||||
ERROR_NO_ROOT(2),
|
ERROR_NO_ROOT(2),
|
||||||
|
ERROR_BAD_RESPONSE(3),
|
||||||
ERROR_REQUEST_FAILED(5);
|
ERROR_REQUEST_FAILED(5);
|
||||||
|
|
||||||
private final int id;
|
private final int id;
|
||||||
@@ -141,6 +144,8 @@ public class Error {
|
|||||||
|
|
||||||
public static String humanString(Type in) {
|
public static String humanString(Type in) {
|
||||||
switch (in) {
|
switch (in) {
|
||||||
|
case ERROR_BAD_RESPONSE:
|
||||||
|
return "Bad answer from server. It's a server side error, wait a bit an retry later.";
|
||||||
case NETWORK_ISSUE:
|
case NETWORK_ISSUE:
|
||||||
return "Could not connect to the server, please check if you have connectivity issue";
|
return "Could not connect to the server, please check if you have connectivity issue";
|
||||||
case TOO_OLD_CLIENT:
|
case TOO_OLD_CLIENT:
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ import org.xml.sax.SAXException;
|
|||||||
import com.sheepit.client.Configuration.ComputeType;
|
import com.sheepit.client.Configuration.ComputeType;
|
||||||
import com.sheepit.client.Error.ServerCode;
|
import com.sheepit.client.Error.ServerCode;
|
||||||
import com.sheepit.client.exception.FermeException;
|
import com.sheepit.client.exception.FermeException;
|
||||||
|
import com.sheepit.client.exception.FermeExceptionBadResponseFromServer;
|
||||||
import com.sheepit.client.exception.FermeExceptionNoRightToRender;
|
import com.sheepit.client.exception.FermeExceptionNoRightToRender;
|
||||||
import com.sheepit.client.exception.FermeExceptionNoSession;
|
import com.sheepit.client.exception.FermeExceptionNoSession;
|
||||||
import com.sheepit.client.exception.FermeExceptionNoSpaceLeftOnDevice;
|
import com.sheepit.client.exception.FermeExceptionNoSpaceLeftOnDevice;
|
||||||
@@ -254,6 +255,9 @@ public class Server extends Thread implements HostnameVerifier, X509TrustManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (r == HttpURLConnection.HTTP_OK && contentType.startsWith("text/html")) {
|
||||||
|
return Error.Type.ERROR_BAD_RESPONSE;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
this.log.error("Server::getConfiguration: Invalid response " + contentType + " " + r);
|
this.log.error("Server::getConfiguration: Invalid response " + contentType + " " + r);
|
||||||
return Error.Type.WRONG_CONFIGURATION;
|
return Error.Type.WRONG_CONFIGURATION;
|
||||||
@@ -443,6 +447,9 @@ public class Server extends Thread implements HostnameVerifier, X509TrustManager
|
|||||||
// most likely varnish is up but apache down
|
// most likely varnish is up but apache down
|
||||||
throw new FermeServerDown();
|
throw new FermeServerDown();
|
||||||
}
|
}
|
||||||
|
else if (r == HttpURLConnection.HTTP_OK && contentType.startsWith("text/html")) {
|
||||||
|
throw new FermeExceptionBadResponseFromServer();
|
||||||
|
}
|
||||||
InputStream in = connection.getInputStream();
|
InputStream in = connection.getInputStream();
|
||||||
String line;
|
String line;
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8"));
|
||||||
@@ -732,6 +739,9 @@ public class Server extends Thread implements HostnameVerifier, X509TrustManager
|
|||||||
}
|
}
|
||||||
return ServerCode.OK;
|
return ServerCode.OK;
|
||||||
}
|
}
|
||||||
|
else if (r == HttpURLConnection.HTTP_OK && contentType.startsWith("text/html")) {
|
||||||
|
return ServerCode.ERROR_BAD_RESPONSE;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
try {
|
try {
|
||||||
inStream = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
inStream = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.sheepit.client.exception;
|
||||||
|
|
||||||
|
public class FermeExceptionBadResponseFromServer extends FermeException {
|
||||||
|
public FermeExceptionBadResponseFromServer() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public FermeExceptionBadResponseFromServer(String message_) {
|
||||||
|
super(message_);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user