Skip to content

Commit

Permalink
added failure description when a request fails being sent, added java…
Browse files Browse the repository at this point in the history
…doc to exception constructor
  • Loading branch information
rob93c committed Oct 6, 2023
1 parent ae8257d commit 21632cb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private void answerText(Answer answer, TelegramRequest request) {
try {
execute(answerWithText);
} catch (TelegramApiException e) {
LOGGER.atError().log("Unable to reply to {} with {}", request, answerWithText);
LOGGER.atError().setCause(e).log("Unable to reply to {}", request);
}
}

Expand All @@ -172,7 +172,7 @@ private <T extends BaseRequest<T, R>, R extends BaseResponse> R execute(BaseRequ
return response;
}

throw new TelegramApiException("Telegram couldn't execute the {} request", request.getMethod());
throw new TelegramApiException("Telegram couldn't execute the {} request: {}", request.getMethod(), response.description());
}

private static void deleteTempFiles(Set<Path> pathsToDelete) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ public TelegramApiException(String message, Throwable cause) {
super(message, cause);
}

/**
* Creates an exception with a parameterized message: each {@code {}}
* will be replaced with the corresponding element in {@code parameters}.
*
* @param message the exception message
* @param parameters the parameters to insert into the message
* @see MessageFormatter#basicArrayFormat(String, Object[])
*/
public TelegramApiException(String message, Object... parameters) {
this(MessageFormatter.basicArrayFormat(message, parameters));
}
Expand Down

0 comments on commit 21632cb

Please sign in to comment.