2014-05-30 08:53:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 10:23:14 +00:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2018-01-03 10:23:14 +00:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2014-05-30 08:53:19 +00:00
|
|
|
*/
|
2016-03-23 18:43:12 +00:00
|
|
|
#include "mtproto/rpc_sender.h"
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2018-06-02 14:29:21 +00:00
|
|
|
RPCError::RPCError(const MTPrpcError &error)
|
|
|
|
: _code(error.c_rpc_error().verror_code.v) {
|
|
|
|
QString text = qs(error.c_rpc_error().verror_message);
|
|
|
|
if (_code < 0 || _code >= 500) {
|
|
|
|
_type = qsl("INTERNAL_SERVER_ERROR");
|
|
|
|
_description = text;
|
|
|
|
} else {
|
|
|
|
const auto expression = QRegularExpression(
|
|
|
|
"^([A-Z0-9_]+)(: .*)?$",
|
|
|
|
reMultiline);
|
|
|
|
const auto match = expression.match(text);
|
|
|
|
if (match.hasMatch()) {
|
|
|
|
_type = match.captured(1);
|
|
|
|
_description = match.captured(2).mid(2);
|
|
|
|
} else {
|
|
|
|
_type = qsl("CLIENT_BAD_RPC_ERROR");
|
|
|
|
_description = qsl("Bad rpc error received, text = '") + text + '\'';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
RPCOwnedDoneHandler::RPCOwnedDoneHandler(RPCSender *owner) : _owner(owner) {
|
2018-06-02 14:29:21 +00:00
|
|
|
_owner->rpcRegHandler(this);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RPCOwnedDoneHandler::~RPCOwnedDoneHandler() {
|
2018-06-02 14:29:21 +00:00
|
|
|
if (_owner) {
|
|
|
|
_owner->rpcUnregHandler(this);
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RPCOwnedFailHandler::RPCOwnedFailHandler(RPCSender *owner) : _owner(owner) {
|
2018-06-02 14:29:21 +00:00
|
|
|
_owner->rpcRegHandler(this);
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
RPCOwnedFailHandler::~RPCOwnedFailHandler() {
|
2018-06-02 14:29:21 +00:00
|
|
|
if (_owner) {
|
|
|
|
_owner->rpcUnregHandler(this);
|
|
|
|
}
|
2014-05-30 08:53:19 +00:00
|
|
|
}
|