Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 4a91afd

Browse files
Added close channel on exception
1 parent 639006c commit 4a91afd

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/main/java/net/cryptic_game/server/microservice/MicroServiceHandler.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,21 @@
99
import org.json.simple.JSONObject;
1010
import org.json.simple.parser.JSONParser;
1111
import org.json.simple.parser.ParseException;
12+
import org.slf4j.Logger;
13+
import org.slf4j.LoggerFactory;
1214

1315
import java.util.UUID;
1416

15-
import static net.cryptic_game.server.error.ServerError.*;
17+
import static net.cryptic_game.server.error.ServerError.MISSING_ACTION;
18+
import static net.cryptic_game.server.error.ServerError.MISSING_PARAMETERS;
19+
import static net.cryptic_game.server.error.ServerError.UNKNOWN_ACTION;
20+
import static net.cryptic_game.server.error.ServerError.UNSUPPORTED_FORMAT;
1621
import static net.cryptic_game.server.socket.SocketServerUtils.sendRaw;
1722

1823
public class MicroServiceHandler extends SimpleChannelInboundHandler<String> {
1924

25+
private static final Logger log = LoggerFactory.getLogger(MicroServiceHandler.class);
26+
2027
@Override
2128
protected void channelRead0(ChannelHandlerContext ctx, String msg) {
2229
Channel channel = ctx.channel();
@@ -119,4 +126,9 @@ public void handlerRemoved(ChannelHandlerContext ctx) {
119126
MicroService.unregister(ctx.channel());
120127
}
121128

129+
@Override
130+
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
131+
log.error("Error in channel " + ctx.toString(), cause);
132+
ctx.close().syncUninterruptibly();
133+
}
122134
}

0 commit comments

Comments
 (0)