java: added request status check for file

This commit is contained in:
Vladimir Kurguzov
2022-11-10 19:05:32 +03:00
committed by Sergey Linnik
parent b6645427a8
commit be1fa2da14
2 changed files with 14 additions and 0 deletions

View File

@ -143,6 +143,12 @@ public class ServiceConverter
}
connection.connect();
int statusCode = connection.getResponseCode();
if (statusCode != 200) { // checking status code
connection.disconnect();
throw new Exception("Conversion service returned status: " + statusCode);
}
try (OutputStream os = connection.getOutputStream()) {
os.write(bodyByte);
}

View File

@ -253,6 +253,14 @@ public class TrackManager {
URL uri = new URL(url);
java.net.HttpURLConnection connection = (java.net.HttpURLConnection) uri.openConnection();
connection.setConnectTimeout(5000);
int statusCode = connection.getResponseCode();
if (statusCode != 200) { // checking status code
connection.disconnect();
throw new RuntimeException("Document editing service returned status: " + statusCode);
}
InputStream stream = connection.getInputStream(); // get input stream of the file information from the url
if (stream == null)