Print errors in the console if exceptions are not handled (#50)
This commit is contained in:
parent
6010390c37
commit
32e936bee0
@ -1,6 +1,8 @@
|
|||||||
package it.tdlight.client;
|
package it.tdlight.client;
|
||||||
|
|
||||||
import it.tdlight.jni.TdApi;
|
import it.tdlight.jni.TdApi;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for incoming responses from TDLib.
|
* Interface for incoming responses from TDLib.
|
||||||
@ -12,12 +14,4 @@ public interface GenericResultHandler<T extends TdApi.Object> {
|
|||||||
* Callback called when TDLib responds.
|
* Callback called when TDLib responds.
|
||||||
*/
|
*/
|
||||||
void onResult(Result<T> result);
|
void onResult(Result<T> result);
|
||||||
|
|
||||||
default void onResult(TdApi.Object result) {
|
|
||||||
onResult(Result.of(result));
|
|
||||||
}
|
|
||||||
|
|
||||||
default void onErrorResult(Throwable exception) {
|
|
||||||
onResult(Result.ofError(exception));
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -27,7 +27,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class SimpleTelegramClient implements Authenticable {
|
public final class SimpleTelegramClient implements Authenticable {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(SimpleTelegramClient.class);
|
public static final Logger LOG = LoggerFactory.getLogger(SimpleTelegramClient.class);
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
@ -39,7 +39,7 @@ public final class SimpleTelegramClient implements Authenticable {
|
|||||||
//noinspection deprecation
|
//noinspection deprecation
|
||||||
Log.setVerbosityLevel(1);
|
Log.setVerbosityLevel(1);
|
||||||
} catch (Throwable ex) {
|
} catch (Throwable ex) {
|
||||||
logger.warn("Can't set verbosity level", ex);
|
LOG.warn("Can't set verbosity level", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ public final class SimpleTelegramClient implements Authenticable {
|
|||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
if (!handled) {
|
if (!handled) {
|
||||||
logger.warn("An update was not handled, please use addUpdateHandler(handler) before starting the client!");
|
LOG.warn("An update was not handled, please use addUpdateHandler(handler) before starting the client!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,7 +103,7 @@ public final class SimpleTelegramClient implements Authenticable {
|
|||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
if (!handled) {
|
if (!handled) {
|
||||||
logger.warn("Error received from Telegram!", ex);
|
LOG.warn("Error received from Telegram!", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,10 +114,14 @@ public final class SimpleTelegramClient implements Authenticable {
|
|||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
if (!handled) {
|
if (!handled) {
|
||||||
logger.warn("Unhandled exception!", ex);
|
LOG.warn("Unhandled exception!", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void handleResultHandlingException(Throwable ex) {
|
||||||
|
LOG.error("Failed to handle the request result", ex);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AuthenticationData getAuthenticationData() {
|
public AuthenticationData getAuthenticationData() {
|
||||||
return authenticationData;
|
return authenticationData;
|
||||||
@ -148,7 +152,7 @@ public final class SimpleTelegramClient implements Authenticable {
|
|||||||
if (update instanceof TdApi.Update) {
|
if (update instanceof TdApi.Update) {
|
||||||
handler.onUpdate((TdApi.Update) update);
|
handler.onUpdate((TdApi.Update) update);
|
||||||
} else {
|
} else {
|
||||||
logger.warn("Unknown update type: {}", update);
|
LOG.warn("Unknown update type: {}", update);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -205,7 +209,7 @@ public final class SimpleTelegramClient implements Authenticable {
|
|||||||
* Send a function and get the result
|
* Send a function and get the result
|
||||||
*/
|
*/
|
||||||
public <T extends TdApi.Object> void send(TdApi.Function function, GenericResultHandler<T> resultHandler) {
|
public <T extends TdApi.Object> void send(TdApi.Function function, GenericResultHandler<T> resultHandler) {
|
||||||
client.send(function, resultHandler::onResult, resultHandler::onErrorResult);
|
client.send(function, result -> resultHandler.onResult(Result.of(result)), this::handleResultHandlingException);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user