comparison src/luan/modules/url/LuanUrl.java @ 1519:3ebf9781707c

http error handling
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 19 Jun 2020 20:10:47 -0600
parents fb5be0e8ca54
children 0160650180bc
comparison
equal deleted inserted replaced
1518:f989778ca9e1 1519:3ebf9781707c
324 throw new RuntimeException(auth.type); 324 throw new RuntimeException(auth.type);
325 } catch(ParseException pe) { 325 } catch(ParseException pe) {
326 throw new LuanException(pe); 326 throw new LuanException(pe);
327 } 327 }
328 } 328 }
329 String msg = "" + responseCode;
329 String responseMessage = httpCon.getResponseMessage(); 330 String responseMessage = httpCon.getResponseMessage();
331 if( responseMessage != null )
332 msg += " - " + responseMessage;
333 String responseContent = null;
330 InputStream is = httpCon.getErrorStream(); 334 InputStream is = httpCon.getErrorStream();
331 if( is == null ) 335 if( is != null ) {
332 throw e; 336 Reader in = new InputStreamReader(is);
333 Reader in = new InputStreamReader(is); 337 responseContent = IoUtils.readAll(in);
334 String msg = IoUtils.readAll(in); 338 in.close();
335 in.close(); 339 msg += "\n" + responseContent;
340 }
336 LuanException le = new LuanException(msg,e); 341 LuanException le = new LuanException(msg,e);
337 le.put("response_code",responseCode); 342 le.put("response_code",responseCode);
338 le.put("response_message",responseMessage); 343 le.put("response_message",responseMessage);
344 le.put("response_content",responseContent);
339 throw le; 345 throw le;
340 } 346 }
341 } 347 }
342 348
343 @Override public String to_string() { 349 @Override public String to_string() {