Skip to content

Commit 02bc21f

Browse files
committed
enchance error logging
1 parent ba6ba4e commit 02bc21f

3 files changed

Lines changed: 25 additions & 7 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ HttpProxyCacheServer proxy = HttpProxyCacheServer.Builder(context)
140140
See `sample` app.
141141

142142
## Known problems
143-
`AndroidVideoCache` [doesn't work](https://github.com/danikula/AndroidVideoCache/issues/28) if wifi or mobile internet connection uses proxy.
143+
- `AndroidVideoCache` [doesn't work](https://github.com/danikula/AndroidVideoCache/issues/28) if wifi or mobile internet connection uses proxy.
144+
- In some cases clients [can't connect](https://github.com/danikula/AndroidVideoCache/issues/134) to local proxy server ('Error pinging server' error). May be it is result of previous error. Note in this case video will be played, but without caching.
144145

145146
## Whats new
146147
See Release Notes [here](https://github.com/danikula/AndroidVideoCache/releases)

library/src/main/java/com/danikula/videocache/Pinger.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@
55

66
import java.io.IOException;
77
import java.io.OutputStream;
8+
import java.net.Proxy;
9+
import java.net.ProxySelector;
810
import java.net.Socket;
11+
import java.net.URI;
12+
import java.net.URISyntaxException;
913
import java.util.Arrays;
14+
import java.util.List;
1015
import java.util.Locale;
1116
import java.util.concurrent.Callable;
1217
import java.util.concurrent.ExecutionException;
@@ -61,13 +66,23 @@ boolean ping(int maxAttempts, int startTimeout) {
6166
attempts++;
6267
timeout *= 2;
6368
}
64-
String error = String.format("Error pinging server (attempts: %d, max timeout: %d). " +
65-
"If you see this message, please, email me danikula@gmail.com " +
66-
"or create issue here https://github.com/danikula/AndroidVideoCache/issues", attempts, timeout / 2);
69+
String error = String.format(Locale.US, "Error pinging server (attempts: %d, max timeout: %d). " +
70+
"If you see this message, please, report at https://github.com/danikula/AndroidVideoCache/issues/134. " +
71+
"Default proxies are: %s"
72+
, attempts, timeout / 2, getDefaultProxies());
6773
LOG.error(error, new ProxyCacheException(error));
6874
return false;
6975
}
7076

77+
private List<Proxy> getDefaultProxies() {
78+
ProxySelector proxySelector = ProxySelector.getDefault();
79+
try {
80+
return proxySelector.select(new URI("https://github.com"));
81+
} catch (URISyntaxException e) {
82+
throw new IllegalStateException(e);
83+
}
84+
}
85+
7186
boolean isPingRequest(String request) {
7287
return PING_REQUEST.equals(request);
7388
}

library/src/main/java/com/danikula/videocache/ProxyCacheException.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77
*/
88
public class ProxyCacheException extends Exception {
99

10+
private static final String LIBRARY_VERSION = ". Version: " + BuildConfig.VERSION_NAME;
11+
1012
public ProxyCacheException(String message) {
11-
super(message);
13+
super(message + LIBRARY_VERSION);
1214
}
1315

1416
public ProxyCacheException(String message, Throwable cause) {
15-
super(message, cause);
17+
super(message + LIBRARY_VERSION, cause);
1618
}
1719

1820
public ProxyCacheException(Throwable cause) {
19-
super(cause);
21+
super("No explanation error" + LIBRARY_VERSION, cause);
2022
}
2123
}

0 commit comments

Comments
 (0)