Skip to content

Commit

Permalink
Merge pull request #1012 from TelegramBots/develop
Browse files Browse the repository at this point in the history
Make exceptions parser public
  • Loading branch information
tuscen authored Aug 1, 2021
2 parents bea959f + 2849ef2 commit 658492a
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .azure-pipelines/variables.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ variables:
- name: versionPrefix
value: 17.0.0
- name: versionSuffix
value: "alpha.1"
value: "alpha.2"
- name: ciVersionSuffix
value: ci.$(Build.BuildId)+git.commit.$(Build.SourceVersion)
- name: buildConfiguration
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/).

<!-- markdownlint-configure-file { "MD024": false } -->

## [Unreleased]

### Added
- Interface `IExceptionsParser`
- Type `ApiResponse`
- Property `ITelegramBotClient.ExceptionsParser`

## [v.16.0.2] - 2021-08-16
### Fixed
- Parameter name `ChatLocation.String` replaced with `ChatLocation.Address`

## [v16.0.1] - 2021-07-10

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# .NET Client for Telegram Bot API

[![package](https://img.shields.io/nuget/vpre/Telegram.Bot.svg?label=Telegram.Bot&style=flat-square)](https://www.nuget.org/packages/Telegram.Bot)
[![Bot API Version](https://img.shields.io/badge/Bot%20API-5.2%20(April%2026,%202021)-f36caf.svg?style=flat-square)](https://core.telegram.org/bots/api)
[![Bot API Version](https://img.shields.io/badge/Bot%20API-5.2%20(June%2025,%202021)-f36caf.svg?style=flat-square)](https://core.telegram.org/bots/api)
[![documentations](https://img.shields.io/badge/Documentations-Book-orange.svg?style=flat-square)](https://telegrambots.github.io/book/)
[![telegram chat](https://img.shields.io/badge/Support_Chat-Telegram-blue.svg?style=flat-square)](https://t.me/joinchat/B35YY0QbLfd034CFnvCtCA)

Expand Down
11 changes: 3 additions & 8 deletions src/Telegram.Bot/Exceptions/ApiRequestException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ public ApiRequestException(string message)
/// <param name="message">The message.</param>
/// <param name="errorCode">The error code.</param>
public ApiRequestException(string message, int errorCode)
: base(message)
{
: base(message) =>
ErrorCode = errorCode;
}

/// <summary>
/// Initializes a new instance of the <see cref="ApiRequestException"/> class.
Expand All @@ -50,8 +48,7 @@ public ApiRequestException(string message, int errorCode)
/// </param>
public ApiRequestException(string message, Exception innerException)
: base(message, innerException)
{
}
{ }

/// <summary>
/// Initializes a new instance of the <see cref="ApiRequestException"/> class.
Expand All @@ -60,10 +57,8 @@ public ApiRequestException(string message, Exception innerException)
/// <param name="errorCode">The error code.</param>
/// <param name="innerException">The inner exception.</param>
public ApiRequestException(string message, int errorCode, Exception innerException)
: base(message, innerException)
{
: base(message, innerException) =>
ErrorCode = errorCode;
}

/// <summary>
/// Initializes a new instance of the <see cref="ApiRequestException"/> class
Expand Down
2 changes: 1 addition & 1 deletion src/Telegram.Bot/Exceptions/ApiResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Telegram.Bot.Exceptions
/// Represents failed API response
/// </summary>
[JsonObject(MemberSerialization.OptIn, NamingStrategyType = typeof(SnakeCaseNamingStrategy))]
internal class ApiResponse
public class ApiResponse
{
/// <summary>
/// Gets the error message.
Expand Down
12 changes: 12 additions & 0 deletions src/Telegram.Bot/Exceptions/DefaultExceptionParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Telegram.Bot.Exceptions
{
internal class DefaultExceptionParser : IExceptionParser
{
public ApiRequestException Parse(ApiResponse apiResponse) =>
new(
message: apiResponse.Description,
errorCode: apiResponse.ErrorCode,
parameters: apiResponse.Parameters
);
}
}
8 changes: 0 additions & 8 deletions src/Telegram.Bot/Exceptions/ExceptionParser.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/Telegram.Bot/Exceptions/IExceptionParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Telegram.Bot.Exceptions
/// <summary>
/// Parses unsuccessful responses from Telegram Bot API to make specific exceptions
/// </summary>
internal interface IExceptionParser
public interface IExceptionParser
{
/// <summary>
/// Parses HTTP response and constructs a specific exception out of it
Expand Down
8 changes: 2 additions & 6 deletions src/Telegram.Bot/Exceptions/RequestException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,8 @@ public RequestException(string message, Exception innerException)
/// <see cref="HttpStatusCode"/> of the received response
/// </param>
public RequestException(string message, HttpStatusCode httpStatusCode)
: base(message)
{
: base(message) =>
HttpStatusCode = httpStatusCode;
}

/// <summary>
/// Initializes a new instance of the <see cref="RequestException"/> class.
Expand All @@ -64,9 +62,7 @@ public RequestException(string message, HttpStatusCode httpStatusCode)
/// (Nothing in Visual Basic) if no inner exception is specified.
/// </param>
public RequestException(string message, HttpStatusCode httpStatusCode, Exception innerException)
: base(message, innerException)
{
: base(message, innerException) =>
HttpStatusCode = httpStatusCode;
}
}
}
8 changes: 8 additions & 0 deletions src/Telegram.Bot/ITelegramBotClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading;
using System.Threading.Tasks;
using Telegram.Bot.Args;
using Telegram.Bot.Exceptions;
using Telegram.Bot.Requests.Abstractions;
using File = Telegram.Bot.Types.File;

Expand All @@ -26,6 +27,13 @@ public interface ITelegramBotClient
/// </summary>
TimeSpan Timeout { get; set; }

/// <summary>
/// Instance of <see cref="IExceptionParser"/> to parse errors from Bot API into
/// <see cref="ApiRequestException"/>
/// </summary>
/// <remarks>This property is not thread safe</remarks>
IExceptionParser ExceptionsParser { get; set; }

/// <summary>
/// Occurs before sending a request to API
/// </summary>
Expand Down
Loading

0 comments on commit 658492a

Please sign in to comment.