env-js
env-js copied to clipboard
Rhino XHR 404 Response Error
In Rhino/Java, a 404 status received from a resource generates and FileNotFound exception. Depending on the server action and content type, an error stream may or may not be available. This patch checks to ensure the stream is defined before attempting to read from it.
--- /env-js/envjs/platform/rhino.js 2011-04-07 21:37:32.000000000 -0600
+++ envjs/platform/rhino.js 2011-04-11 12:22:42.000000000 -0600
@@ -385,12 +385,14 @@
instream = connection.getErrorStream();
}
- while ((length = instream.read(buffer, 0, 1024)) != -1) {
- outstream.write(buffer, 0, length);
+ if (instream) {
+ while ((length = instream.read(buffer, 0, 1024)) != -1) {
+ outstream.write(buffer, 0, length);
+ }
+ instream.close();
}
outstream.close();
- instream.close();
if(binary){
xhr.responseText = new java.lang.String(outstream.toByteArray(), 'UTF-8')+'';