Skip to content

Commit 1c1e0a3

Browse files
committed
Log connection time outs with debug level.
1 parent 5ef82ee commit 1c1e0a3

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

src/main/java/com/beowulfe/hap/impl/http/impl/AccessoryHandler.java

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
package com.beowulfe.hap.impl.http.impl;
22

3+
import com.beowulfe.hap.impl.http.HomekitClientConnection;
4+
import com.beowulfe.hap.impl.http.HomekitClientConnectionFactory;
5+
import com.beowulfe.hap.impl.http.HttpResponse;
36
import io.netty.buffer.Unpooled;
4-
import io.netty.channel.*;
7+
import io.netty.channel.Channel;
8+
import io.netty.channel.ChannelHandlerContext;
9+
import io.netty.channel.ChannelPipeline;
10+
import io.netty.channel.SimpleChannelInboundHandler;
511
import io.netty.handler.codec.http.*;
6-
7-
import java.nio.charset.StandardCharsets;
8-
912
import org.slf4j.Logger;
1013
import org.slf4j.LoggerFactory;
1114

12-
import com.beowulfe.hap.impl.http.*;
13-
import com.beowulfe.hap.impl.http.HttpResponse;
15+
import java.io.IOException;
16+
import java.nio.charset.StandardCharsets;
1417

1518
class AccessoryHandler extends SimpleChannelInboundHandler<FullHttpRequest> {
1619

@@ -84,7 +87,16 @@ public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
8487
@Override
8588
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
8689
throws Exception {
87-
LOGGER.error("Exception caught in web handler", cause);
90+
boolean errorLevel = true;
91+
if (cause instanceof IOException) {
92+
// Decide level of logging based on exception
93+
errorLevel = !"Connection timed out".equals(cause.getMessage());
94+
}
95+
if (errorLevel) {
96+
LOGGER.error("Exception caught in web handler", cause);
97+
} else {
98+
LOGGER.debug("Exception caught in web handler", cause);
99+
}
88100
ctx.close();
89101
}
90102
}

src/main/java/com/beowulfe/hap/impl/http/impl/BinaryHandler.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
package com.beowulfe.hap.impl.http.impl;
22

3+
import com.beowulfe.hap.impl.http.HomekitClientConnection;
34
import io.netty.buffer.ByteBuf;
45
import io.netty.buffer.Unpooled;
56
import io.netty.channel.ChannelHandlerContext;
67
import io.netty.handler.codec.ByteToMessageCodec;
7-
8-
import java.io.ByteArrayOutputStream;
9-
import java.nio.charset.StandardCharsets;
10-
import java.util.List;
11-
128
import org.apache.commons.io.HexDump;
139
import org.slf4j.Logger;
1410
import org.slf4j.LoggerFactory;
1511

16-
import com.beowulfe.hap.impl.http.HomekitClientConnection;
12+
import java.io.ByteArrayOutputStream;
13+
import java.io.IOException;
14+
import java.nio.charset.StandardCharsets;
15+
import java.util.List;
1716

1817
public class BinaryHandler extends ByteToMessageCodec<ByteBuf> {
1918

@@ -53,7 +52,16 @@ protected void decode(ChannelHandlerContext ctx, ByteBuf in,
5352
@Override
5453
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
5554
throws Exception {
56-
logger.error("Exception in binary handler", cause);
55+
boolean errorLevel = true;
56+
if (cause instanceof IOException) {
57+
// Decide level of logging based on exception
58+
errorLevel = !"Connection timed out".equals(cause.getMessage());
59+
}
60+
if (errorLevel) {
61+
logger.error("Exception in binary handler", cause);
62+
} else {
63+
logger.debug("Exception in binary handler", cause);
64+
}
5765
super.exceptionCaught(ctx, cause);
5866
}
5967

0 commit comments

Comments
 (0)