Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark derived exceptions obsolete #694

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 1 addition & 63 deletions src/Telegram.Bot/Exceptions/ApiException.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using Telegram.Bot.Types;

namespace Telegram.Bot.Exceptions
Expand Down Expand Up @@ -96,68 +96,6 @@ public ApiRequestException(string message, int errorCode, ResponseParameters par
public static ApiRequestException FromApiResponse<T>(ApiResponse<T> apiResponse)
{
return ApiExceptionParser.Parse<T>(apiResponse);
/*
string message;
switch (apiResponse.ErrorCode)
{
//TODO: Add test cases for all those
case 400:
message = apiResponse.Description.Remove(0, "Bad Request: ".Length);
switch (message.Trim())
{
case "have no rights to send a message":
return new BotRestrictedException(apiResponse.Description)
{
Parameters = apiResponse.Parameters
};
case "not enough rights to restrict/unrestrict chat member":
return new NotEnoughRightsException(apiResponse.Description)
{
Parameters = apiResponse.Parameters
};
case "method is available for supergroup and channel chats only":
return new WrongChatTypeException(apiResponse.Description)
{
Parameters = apiResponse.Parameters
};
default:
if (message.EndsWith(" is empty"))
{
return new MissingParameterException(apiResponse.Description, message.Remove(message.IndexOf(" is empty")))
{
Parameters = apiResponse.Parameters
};
}
LogMissingError(apiResponse);
return new ApiRequestException(apiResponse.Description, 400)
{
Parameters = apiResponse.Parameters
};
}
case 403:
message = apiResponse.Description.Remove(0, "Forbidden: ".Length);
switch (message.Trim())
{
case "bot was blocked by the user":
return new BotBlockedException(apiResponse.Description)
{
Parameters = apiResponse.Parameters
};
default:
LogMissingError(apiResponse);
return new ApiRequestException(apiResponse.Description, 403)
{
Parameters = apiResponse.Parameters
};
}
default:
LogMissingError(apiResponse);
return new ApiRequestException(apiResponse.Description, apiResponse.ErrorCode)
{
Parameters = apiResponse.Parameters
};
}
*/
}
}
}
2 changes: 1 addition & 1 deletion src/Telegram.Bot/Exceptions/BadRequestException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Telegram.Bot.Exceptions
/// <summary>
/// Represents an error from Bot API with 400 Bad Request HTTP status
/// </summary>
public abstract class BadRequestException : ApiRequestException
public class BadRequestException : ApiRequestException
{
/// <inheritdoc />
public override int ErrorCode => BadRequestErrorCode;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// ReSharper disable once CheckNamespace
using System;

// ReSharper disable once CheckNamespace
namespace Telegram.Bot.Exceptions
{
/// <summary>
/// The exception that is thrown when the chat does not exist
/// </summary>
[Obsolete]
public class ChatNotFoundException : BadRequestException
{
/// <summary>
Expand All @@ -15,4 +18,4 @@ public ChatNotFoundException(string message)
{
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// ReSharper disable once CheckNamespace
using System;

// ReSharper disable once CheckNamespace
namespace Telegram.Bot.Exceptions
{
/// <summary>
/// The exception that is thrown when the chat does not exist
/// </summary>
[Obsolete]
public class ContactRequestException : BadRequestException
{
/// <summary>
Expand All @@ -15,4 +18,4 @@ public ContactRequestException(string message)
{
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// ReSharper disable once CheckNamespace
using System;

// ReSharper disable once CheckNamespace
namespace Telegram.Bot.Exceptions
{
/// <summary>
/// The exception that is thrown when the specified game short name is empty, invalid, or wrong(non-existent).
/// </summary>
[Obsolete]
public class InvalidGameShortNameException : InvalidParameterException
{
/// <summary>
Expand All @@ -16,4 +18,4 @@ public InvalidGameShortNameException(string message)
{
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// ReSharper disable once CheckNamespace
using System;

// ReSharper disable once CheckNamespace
namespace Telegram.Bot.Exceptions
{
/// <summary>
/// The exception that is thrown when a parameter is invalid
/// </summary>
[Obsolete]
public class InvalidParameterException : BadRequestException
{
internal const string ParamGroupName = "param";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// ReSharper disable once CheckNamespace
using System;

// ReSharper disable once CheckNamespace
namespace Telegram.Bot.Exceptions
{
/// <summary>
/// The exception that is thrown when Query Id is invalid or AnswerInlineQueryAsync
/// called with 10 second delay
/// </summary>
[Obsolete]
public class InvalidQueryIdException : InvalidParameterException
{
/// <summary>
Expand All @@ -16,4 +19,4 @@ public InvalidQueryIdException(string message)
{
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// ReSharper disable once CheckNamespace
using System;

// ReSharper disable once CheckNamespace
namespace Telegram.Bot.Exceptions
{
/// <summary>
/// The exception that is thrown when the sticker set is invalid
/// </summary>
[Obsolete]
public class InvalidStickerDimensionsException : InvalidParameterException
{
/// <summary>
Expand All @@ -15,4 +18,4 @@ public InvalidStickerDimensionsException(string message)
{
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// ReSharper disable once CheckNamespace
using System;

// ReSharper disable once CheckNamespace
namespace Telegram.Bot.Exceptions
{
/// <summary>
/// The exception that is thrown when the sticker set is invalid
/// </summary>
[Obsolete]
public class InvalidStickerEmojisException : InvalidParameterException
{
/// <summary>
Expand All @@ -15,4 +18,4 @@ public InvalidStickerEmojisException(string message)
{
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// ReSharper disable once CheckNamespace
using System;

// ReSharper disable once CheckNamespace
namespace Telegram.Bot.Exceptions
{
/// <summary>
/// The exception that is thrown when the sticker set is invalid
/// </summary>
[Obsolete]
public class InvalidStickerSetNameException : InvalidParameterException
{
/// <summary>
Expand All @@ -15,4 +18,4 @@ public InvalidStickerSetNameException(string message)
{
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// ReSharper disable once CheckNamespace
using System;

// ReSharper disable once CheckNamespace
namespace Telegram.Bot.Exceptions
{
/// <summary>
/// The exception that is thrown when the user does not exist
/// </summary>
[Obsolete]
public class InvalidUserIdException : InvalidParameterException
{
/// <summary>
Expand All @@ -15,4 +18,4 @@ public InvalidUserIdException(string message)
{
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// ReSharper disable once CheckNamespace
using System;

// ReSharper disable once CheckNamespace
namespace Telegram.Bot.Exceptions
{
/// <summary>
/// The exception that is thrown when the message is not modified
/// </summary>
[Obsolete]
public class MessageIsNotModifiedException : BadRequestException
{
/// <summary>
Expand All @@ -15,4 +18,4 @@ public MessageIsNotModifiedException(string message)
{
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// ReSharper disable once CheckNamespace
using System;

// ReSharper disable once CheckNamespace
namespace Telegram.Bot.Exceptions
{
/// <summary>
/// The exception that is thrown when the sticker set is invalid
/// </summary>
[Obsolete]
public class StickerSetNameExistsException : BadRequestException
{
/// <summary>
Expand All @@ -15,4 +18,4 @@ public StickerSetNameExistsException(string message)
{
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// ReSharper disable once CheckNamespace
using System;

// ReSharper disable once CheckNamespace
namespace Telegram.Bot.Exceptions
{
/// <summary>
/// The exception that is thrown when the sticker set is invalid
/// </summary>
[Obsolete]
public class StickerSetNotModifiedException : BadRequestException
{
/// <summary>
Expand All @@ -15,4 +18,4 @@ public StickerSetNotModifiedException(string message)
{
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
// ReSharper disable once CheckNamespace
using System;

// ReSharper disable once CheckNamespace
namespace Telegram.Bot.Exceptions
{
/// <summary>
/// The exception that is thrown when the user does not exist
/// </summary>
[Obsolete]
public class UserNotFoundException : BadRequestException
{
/// <summary>
Expand All @@ -15,4 +18,4 @@ public UserNotFoundException(string message)
{
}
}
}
}
2 changes: 1 addition & 1 deletion src/Telegram.Bot/Exceptions/ForbiddenException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Telegram.Bot.Exceptions
/// <summary>
/// Represents an error from Bot API with 403 Forbidden HTTP status
/// </summary>
public abstract class ForbiddenException : ApiRequestException
public class ForbiddenException : ApiRequestException
{
/// <inheritdoc />
public override int ErrorCode => ForbiddenErrorCode;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// ReSharper disable once CheckNamespace
using System;

// ReSharper disable once CheckNamespace
namespace Telegram.Bot.Exceptions
{
/// <summary>
/// The exception that is thrown when the bot sends message to
/// a user who has not initiated a chat with bot yet
/// </summary>
[Obsolete]
public class ChatNotInitiatedException : ForbiddenException
{
/// <summary>
Expand Down