Added further details for error on wrong response code

This commit is contained in:
bs
2021-11-15 08:29:50 +01:00
parent ec7c196052
commit 0859d47df0
+24 -2
View File
@@ -7,6 +7,7 @@ import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.HttpURLConnection;
@@ -55,7 +56,7 @@ public class Main
*/
private static Triplet refreshInfo;
private static void writeError(String text)
private static void writeError(String text, InputStream errorStream)
{
if (errorFile == null)
{
@@ -66,11 +67,32 @@ public class Main
{
bout.write(text);
bout.newLine();
if (errorStream!= null)
{
BufferedReader bin = new BufferedReader(new InputStreamReader(errorStream));
String errorLine = bin.readLine();
while (errorLine != null)
{
bout.write(" **** "+errorLine);
bout.newLine();
errorLine = bin.readLine();
}
bin.close();
}
}
catch (IOException e)
{
}
}
private static void writeError(String text)
{
writeError(text, null);
}
/**
* For testing: ensures the test requests are used
@@ -478,7 +500,7 @@ public class Main
// excluded error messages appearing on missing streams and reached rate limit
if (responseCode != HttpURLConnection.HTTP_NOT_FOUND && responseCode != httpCodeLimitReached)
{
writeError("Athlete: " + athleteId + " Wrong response code: " + responseCode);
writeError("Athlete: " + athleteId + " Wrong response code: " + responseCode, connection.getErrorStream());
}
throw new ResponseCodeWrongException(responseCode);
}