Mercurial Hosting > luan
comparison src/luan/modules/url/LuanUrl.java @ 1094:cb4c20fce7d0
add "response_code" and "response_message" to http url luan exceptions
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 24 Jan 2017 14:14:43 -0700 |
parents | 4aab4dd3ac9c |
children | 0842b9b570f8 |
comparison
equal
deleted
inserted
replaced
1093:a656fa45e315 | 1094:cb4c20fce7d0 |
---|---|
271 | 271 |
272 private static InputStream getInputStream(HttpURLConnection httpCon) throws IOException, LuanException { | 272 private static InputStream getInputStream(HttpURLConnection httpCon) throws IOException, LuanException { |
273 try { | 273 try { |
274 return httpCon.getInputStream(); | 274 return httpCon.getInputStream(); |
275 } catch(IOException e) { | 275 } catch(IOException e) { |
276 int responseCode = httpCon.getResponseCode(); | |
277 String responseMessage = httpCon.getResponseMessage(); | |
276 InputStream is = httpCon.getErrorStream(); | 278 InputStream is = httpCon.getErrorStream(); |
277 if( is == null ) | 279 if( is == null ) |
278 throw e; | 280 throw e; |
279 Reader in = new InputStreamReader(is); | 281 Reader in = new InputStreamReader(is); |
280 String msg = Utils.readAll(in); | 282 String msg = Utils.readAll(in); |
281 in.close(); | 283 in.close(); |
282 throw new LuanException(msg,e); | 284 LuanException le = new LuanException(msg,e); |
285 LuanTable tbl = le.table(); | |
286 tbl.rawPut("response_code",responseCode); | |
287 tbl.rawPut("response_message",responseMessage); | |
288 throw le; | |
283 } | 289 } |
284 } | 290 } |
285 | 291 |
286 @Override public String to_string() { | 292 @Override public String to_string() { |
287 return url.toString(); | 293 return url.toString(); |