From cce5287f941a32ce61bb5ce45585f0844fc02bb4 Mon Sep 17 00:00:00 2001 From: Artem Siryk Date: Tue, 24 Mar 2020 19:09:30 +0000 Subject: [PATCH] errors: renamed Error to ApiError; it now satiesfies `error` --- errors.go | 66 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 35 insertions(+), 31 deletions(-) diff --git a/errors.go b/errors.go index 535f0d5..a8ca136 100644 --- a/errors.go +++ b/errors.go @@ -1,51 +1,55 @@ package telebot -type Error struct { +type ApiError struct { ErrorCode string } +func (err *ApiError) Error() string { + return err.ErrorCode +} + var ( //bot creation errors - ErrUnauthorized = &Error{"Unauthorized"} + ErrUnauthorized = &ApiError{"Unauthorized"} // not found etc - ErrToForwardNotFound = &Error{"Bad Request: message to forward not found"} - ErrToReplyNotFound = &Error{"Bad Request: reply message not found"} - ErrMessageTooLong = &Error{"Bad Request: message is too long"} - ErrBlockedByUsr = &Error{"Forbidden: bot was blocked by the user"} - ErrToDeleteNotFound = &Error{"Bad Request: message to delete not found"} - ErrEmptyMessage = &Error{"Bad Request: message must be non-empty"} + ErrToForwardNotFound = &ApiError{"Bad Request: message to forward not found"} + ErrToReplyNotFound = &ApiError{"Bad Request: reply message not found"} + ErrMessageTooLong = &ApiError{"Bad Request: message is too long"} + ErrBlockedByUsr = &ApiError{"Forbidden: bot was blocked by the user"} + ErrToDeleteNotFound = &ApiError{"Bad Request: message to delete not found"} + ErrEmptyMessage = &ApiError{"Bad Request: message must be non-empty"} //checking - ErrEmptyText = &Error{"Bad Request: text is empty"} - ErrEmptyChatID = &Error{"Bad Request: chat_id is empty"} - ErrNotFoundChat = &Error{"Bad Request: chat not found"} - ErrMessageNotModified = &Error{"Bad Request: message is not modified"} + ErrEmptyText = &ApiError{"Bad Request: text is empty"} + ErrEmptyChatID = &ApiError{"Bad Request: chat_id is empty"} + ErrNotFoundChat = &ApiError{"Bad Request: chat not found"} + ErrMessageNotModified = &ApiError{"Bad Request: message is not modified"} // // Rigts Errors - ErrNoRightsToRestrict = &Error{"Bad Request: not enough rights to restrict/unrestrict chat member"} - ErrNoRightsToSendMsg = &Error{"Bad Request: have no rights to send a message"} - ErrNoRightsToSendPhoto = &Error{"Bad Request: not enough rights to send photos to the chat"} - ErrNoRightsToSendStickers = &Error{"Bad Request: not enough rights to send stickers to the chat"} - ErrNoRightsToSendGifs = &Error{"Bad Request: CHAT_SEND_GIFS_FORBIDDEN"} - ErrNoRightsToDelete = &Error{"Bad Request: message can't be deleted"} - ErrKickingChatOwner = &Error{"Bad Request: can't remove chat owner"} + ErrNoRightsToRestrict = &ApiError{"Bad Request: not enough rights to restrict/unrestrict chat member"} + ErrNoRightsToSendMsg = &ApiError{"Bad Request: have no rights to send a message"} + ErrNoRightsToSendPhoto = &ApiError{"Bad Request: not enough rights to send photos to the chat"} + ErrNoRightsToSendStickers = &ApiError{"Bad Request: not enough rights to send stickers to the chat"} + ErrNoRightsToSendGifs = &ApiError{"Bad Request: CHAT_SEND_GIFS_FORBIDDEN"} + ErrNoRightsToDelete = &ApiError{"Bad Request: message can't be deleted"} + ErrKickingChatOwner = &ApiError{"Bad Request: can't remove chat owner"} // Interacting with group/supergroup after being kicked - ErrInteractKickedG = &Error{"api error: Forbidden: bot was kicked from the group chat"} - ErrInteractKickedSprG = &Error{"Forbidden: bot was kicked from the supergroup chat"} + ErrInteractKickedG = &ApiError{"api error: Forbidden: bot was kicked from the group chat"} + ErrInteractKickedSprG = &ApiError{"Forbidden: bot was kicked from the supergroup chat"} // file errors etc - ErrWrongTypeOfContent = &Error{"Bad Request: wrong type of the web page content"} - ErrCantGetHTTPurlContent = &Error{"Bad Request: failed to get HTTP URL content"} - ErrWrongRemoteFileID = &Error{"Bad Request: wrong remote file id specified: can't unserialize it. Wrong last symbol"} - ErrWrongRemoteFileIDlen = &Error{"Bad Request: wrong remote file id specified: Wrong string length"} - ErrWrongRemoteFileIDsymbol = &Error{"Bad Request: wrong remote file id specified: Wrong character in the string"} - ErrWrongFileIdentifier = &Error{"Bad Request: wrong file identifier/HTTP URL specified"} - ErrTooLarge = &Error{"Request Entity Too Large"} - ErrWrongPadding = &Error{"Bad Request: wrong remote file id specified: Wrong padding in the string"} // not my - ErrImageProcess = &Error{"Bad Request: IMAGE_PROCESS_FAILED"} + ErrWrongTypeOfContent = &ApiError{"Bad Request: wrong type of the web page content"} + ErrCantGetHTTPurlContent = &ApiError{"Bad Request: failed to get HTTP URL content"} + ErrWrongRemoteFileID = &ApiError{"Bad Request: wrong remote file id specified: can't unserialize it. Wrong last symbol"} + ErrWrongRemoteFileIDlen = &ApiError{"Bad Request: wrong remote file id specified: Wrong string length"} + ErrWrongRemoteFileIDsymbol = &ApiError{"Bad Request: wrong remote file id specified: Wrong character in the string"} + ErrWrongFileIdentifier = &ApiError{"Bad Request: wrong file identifier/HTTP URL specified"} + ErrTooLarge = &ApiError{"Request Entity Too Large"} + ErrWrongPadding = &ApiError{"Bad Request: wrong remote file id specified: Wrong padding in the string"} // not my + ErrImageProcess = &ApiError{"Bad Request: IMAGE_PROCESS_FAILED"} // sticker errors - ErrWrongStickerpack = &Error{"Bad Request: STICKERSET_INVALID"} + ErrWrongStickerpack = &ApiError{"Bad Request: STICKERSET_INVALID"} )