init
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled
This commit is contained in:
91
Telegram/SourceFiles/mtproto/mtproto_response.cpp
Normal file
91
Telegram/SourceFiles/mtproto/mtproto_response.cpp
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "mtproto/mtproto_response.h"
|
||||
|
||||
#include <QtCore/QRegularExpression>
|
||||
#include <QtCore/QDebug>
|
||||
|
||||
namespace MTP {
|
||||
namespace {
|
||||
|
||||
[[nodiscard]] MTPrpcError ParseError(const mtpBuffer &reply) {
|
||||
auto result = MTPRpcError();
|
||||
auto from = reply.constData();
|
||||
return result.read(from, from + reply.size())
|
||||
? result
|
||||
: Error::MTPLocal("RESPONSE_PARSE_FAILED", "Error parse failed.");
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Error::Error(const MTPrpcError &error)
|
||||
: _code(error.c_rpc_error().verror_code().v) {
|
||||
QString text = qs(error.c_rpc_error().verror_message());
|
||||
static const auto Expression = QRegularExpression(
|
||||
"^([A-Z0-9_]+)(: .*)?$",
|
||||
(QRegularExpression::DotMatchesEverythingOption
|
||||
| QRegularExpression::MultilineOption));
|
||||
const auto match = Expression.match(text);
|
||||
if (match.hasMatch()) {
|
||||
_type = match.captured(1);
|
||||
_description = match.captured(2).mid(2);
|
||||
} else if (_code < 0 || _code >= 500) {
|
||||
_type = "INTERNAL_SERVER_ERROR";
|
||||
_description = text;
|
||||
} else {
|
||||
_type = "CLIENT_BAD_RPC_ERROR";
|
||||
_description = "Bad rpc error received, text = '" + text + '\'';
|
||||
}
|
||||
}
|
||||
|
||||
Error::Error(const mtpBuffer &reply) : Error(ParseError(reply)) {
|
||||
}
|
||||
|
||||
int32 Error::code() const {
|
||||
return _code;
|
||||
}
|
||||
|
||||
const QString &Error::type() const {
|
||||
return _type;
|
||||
}
|
||||
|
||||
const QString &Error::description() const {
|
||||
return _description;
|
||||
}
|
||||
|
||||
MTPrpcError Error::MTPLocal(
|
||||
const QString &type,
|
||||
const QString &description) {
|
||||
return MTP_rpc_error(
|
||||
MTP_int(0),
|
||||
MTP_bytes(
|
||||
("CLIENT_"
|
||||
+ type
|
||||
+ (description.length()
|
||||
? (": " + description)
|
||||
: QString())).toUtf8()));
|
||||
}
|
||||
|
||||
Error Error::Local(
|
||||
const QString &type,
|
||||
const QString &description) {
|
||||
return Error(MTPLocal(type, description));
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug debug, const Error &error) {
|
||||
return debug.nospace()
|
||||
<< "MTP::Error("
|
||||
<< error.code()
|
||||
<< ", "
|
||||
<< error.type()
|
||||
<< ", "
|
||||
<< error.description()
|
||||
<< ")";
|
||||
}
|
||||
|
||||
} // namespace MTP
|
||||
Reference in New Issue
Block a user