From 73b02518a4b7daec8904e42d0d4e55047b21efcd Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sat, 15 Sep 2018 14:05:12 +0200 Subject: [PATCH] Silent handling of bridge errors No longer reporting breaking pipes on bridges #11 --- .../website/page/BridgePage.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/buttondevteam/website/page/BridgePage.java b/src/buttondevteam/website/page/BridgePage.java index 38f383f..2c62392 100644 --- a/src/buttondevteam/website/page/BridgePage.java +++ b/src/buttondevteam/website/page/BridgePage.java @@ -53,9 +53,13 @@ public class BridgePage extends Page { return new Response(400, "No connection", exchange); if (s.isClosed()) return new Response(410, "Socket Gone", exchange); - exchange.sendResponseHeaders(200, 0); // Chunked transfer, any amount of data - copyStream(s.getInputStream(), exchange.getResponseBody()); - exchange.getResponseBody().close(); // It'll only get here when the communication is already done + try { + exchange.sendResponseHeaders(200, 0); // Chunked transfer, any amount of data + copyStream(s.getInputStream(), exchange.getResponseBody()); + exchange.getResponseBody().close(); // It'll only get here when the communication is already done + } catch (IOException ex) { //Failed to send it over HTTP, GET connection closed + closeSocket(exchange); //We only have one GET, connection over + } return null; // Response already sent case "DELETE": System.out.println("[BWM] [" + id + "] delet this"); @@ -65,7 +69,12 @@ public class BridgePage extends Page { return new Response(403, "Unknown request", exchange); } } catch (IOException e) { - throw new RuntimeException(e); + if (e instanceof SocketException) { + closeSocket(exchange); + return new Response(410, "Socket Gone because of error: " + e, exchange); + } + e.printStackTrace(); + return new Response(500, "Internal Server Error: " + e, exchange); } } @@ -92,8 +101,7 @@ public class BridgePage extends Page { return; try { socket.close(); - } catch (IOException e) { - throw new RuntimeException(e); + } catch (IOException ignored) { } connections.values().remove(socket); }