Mercurial Hosting > luan
changeset 1085:a04da9a3e9eb
improve url delete error handling
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 19 Dec 2016 01:05:10 -0700 |
parents | aa967fd73b80 |
children | b1f6dafa72fc |
files | src/luan/modules/url/LuanUrl.java |
diffstat | 1 files changed, 16 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
diff -r aa967fd73b80 -r a04da9a3e9eb src/luan/modules/url/LuanUrl.java --- a/src/luan/modules/url/LuanUrl.java Sat Nov 26 20:51:14 2016 -0700 +++ b/src/luan/modules/url/LuanUrl.java Mon Dec 19 01:05:10 2016 -0700 @@ -237,7 +237,7 @@ if( method==Method.DELETE ) { httpCon.setRequestMethod("DELETE"); - return httpCon.getInputStream(); + return getInputStream(httpCon); } // POST @@ -257,22 +257,26 @@ } out.flush(); try { - try { - return httpCon.getInputStream(); - } catch(IOException e) { - InputStream is = httpCon.getErrorStream(); - if( is == null ) - throw e; - Reader in = new InputStreamReader(is); - String msg = Utils.readAll(in); - in.close(); - throw new LuanException(msg,e); - } + return getInputStream(httpCon); } finally { out.close(); } } + private static InputStream getInputStream(HttpURLConnection httpCon) throws IOException, LuanException { + try { + return httpCon.getInputStream(); + } catch(IOException e) { + InputStream is = httpCon.getErrorStream(); + if( is == null ) + throw e; + Reader in = new InputStreamReader(is); + String msg = Utils.readAll(in); + in.close(); + throw new LuanException(msg,e); + } + } + @Override public String to_string() { return url.toString(); }