Check out example codes for "java read from connection even if 404". It will help you in understanding the concepts better.

Code Example 1

HttpURLConnection c = (HttpURLConnection)new URL("http://somesite.com").openConnection();
InputStream in = null;
if (c.getResponseCode() >= 400) {
   in = c.getErrorStream();
}  
else {
   in = c.getInputStream();
}

Learn ReactJs, React Native from akashmittal.com