Fix responseerror

This commit is contained in:
Andrea Cavalli 2021-06-02 13:21:54 +02:00
parent 85594c61ea
commit d832f1d55c
1 changed files with 41 additions and 31 deletions

View File

@ -17,59 +17,69 @@ public class ResponseError extends IOException {
private final int code;
@NotNull
private final String message;
private final Throwable cause;
public ResponseError(@NotNull Function function, @NotNull String botName, @NotNull TdApi.Error cause) {
super("Bot '" + botName + "' failed the request '" + functionToInlineString(function) + "': " + cause.code + " " + cause.message);
private ResponseError(@NotNull Function function, @NotNull String botName, @NotNull TdApi.Error tdError, @Nullable Throwable cause) {
super("Bot '" + botName + "' failed the request '" + functionToInlineString(function) + "': " + tdError.code + " " + tdError.message, cause);
this.botName = botName;
this.tag = functionToInlineString(function);
this.code = cause.code;
this.message = cause.message;
this.cause = null;
this.code = tdError.code;
this.message = tdError.message;
}
public ResponseError(@NotNull String tag, @NotNull String botName, @NotNull TdApi.Error cause) {
super("Bot '" + botName + "' failed the request '" + tag + "': " + cause.code + " " + cause.message);
private ResponseError(@NotNull String tag, @NotNull String botName, @NotNull TdApi.Error tdError, @Nullable Throwable cause) {
super("Bot '" + botName + "' failed the request '" + tag + "': " + tdError.code + " " + tdError.message, cause);
this.botName = botName;
this.tag = tag;
this.code = cause.code;
this.message = cause.message;
this.cause = null;
this.code = tdError.code;
this.message = tdError.message;
}
public ResponseError(@NotNull Function function, @NotNull String botName, @NotNull Throwable cause) {
super("Bot '" + botName + "' failed the request '" + functionToInlineString(function) + "': " + cause.getMessage());
private ResponseError(@NotNull Function function, @NotNull String botName, @Nullable Throwable cause) {
super("Bot '" + botName + "' failed the request '" + functionToInlineString(function) + "': " + (cause == null ? null : cause.getMessage()), cause);
this.botName = botName;
this.tag = functionToInlineString(function);
this.code = 500;
this.message = cause.getMessage();
this.cause = cause;
this.initCause(cause);
this.message = (cause == null ? "" : (cause.getMessage() == null ? "" : cause.getMessage()));
}
public ResponseError(@NotNull String tag, @NotNull String botName, @NotNull Throwable cause) {
super("Bot '" + botName + "' failed the request '" + tag + "': " + cause.getMessage());
private ResponseError(@NotNull String tag, @NotNull String botName, @Nullable Throwable cause) {
super("Bot '" + botName + "' failed the request '" + tag + "': " + (cause == null ? null : cause.getMessage()), cause);
this.botName = botName;
this.tag = tag;
this.code = 500;
this.message = cause.getMessage();
this.cause = cause;
this.initCause(cause);
this.message = (cause == null ? "" : (cause.getMessage() == null ? "" : cause.getMessage()));
}
public static ResponseError newResponseError(@NotNull Function function, @NotNull String botName, @NotNull TdApi.Error cause) {
public static ResponseError newResponseError(@NotNull Function function,
@NotNull String botName,
@NotNull TdApi.Error tdError,
@Nullable Throwable cause) {
return new ResponseError(function, botName, tdError, cause);
}
public static ResponseError newResponseError(@NotNull String tag,
@NotNull String botName,
@NotNull TdApi.Error tdError,
@Nullable Throwable cause) {
return new ResponseError(tag, botName, tdError, cause);
}
public static ResponseError newResponseError(@NotNull String tag,
@NotNull String botName,
@NotNull TdApi.Error tdError,
@Nullable TdError cause) {
return new ResponseError(tag, botName, tdError, cause);
}
public static ResponseError newResponseError(@NotNull Function function,
@NotNull String botName,
@Nullable Throwable cause) {
return new ResponseError(function, botName, cause);
}
public static ResponseError newResponseError(@NotNull String tag, @NotNull String botName, @NotNull TdApi.Error cause) {
return new ResponseError(tag, botName, cause);
}
public static ResponseError newResponseError(@NotNull Function function, @NotNull String botName, @NotNull Throwable cause) {
return new ResponseError(function, botName, cause);
}
public static ResponseError newResponseError(@NotNull String tag, @NotNull String botName, @NotNull Throwable cause) {
public static ResponseError newResponseError(@NotNull String tag,
@NotNull String botName,
@Nullable Throwable cause) {
return new ResponseError(tag, botName, cause);
}