result = result + buffer;
}
reader.close();
return result;
} catch (MalformedURLException e) {
throw new AppException("Got Network-related error: wrong URL",
C.NET_ERROR);
} catch (IOException e) {
StringBuffer errBuffer = new StringBuffer();
try {
System.err.println("Code: " + conn.getResponseCode());
InputStream is = conn.getErrorStream();
byte[] data = new byte[is.available()];
is.read(data);
String body = new String(data);
System.err.println("Google said: " + body);
// close flows
if (is != null) {
is.close();
}
if (reader != null) {
reader.close();
}
// make meanful reply in AppException
/*
* Gson gson = new Gson(); GoogleErrStruct jsonWithError =
* gson.fromJson(reader, GoogleErrStruct.class);
* errBuffer.append(jsonWithError.getError());
*/
System.err.println("Header sent was: " + payload);
} catch (IOException e1) {
throw new AppException(
"Got Network-related error: Net I/O while reading response",
C.NET_ERROR);
} catch (NullPointerException npe) {
throw new AppException(
"Got Network-related error: Net I/O while reading response aka NPE",
C.NET_ERROR);
}
throw new AppException("Got " + errBuffer.toString()
+ " error from google", C.NET_ERROR);
}
// return "";
}