2014-05-30 12:53:19 +04:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 13:23:14 +03:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2014-05-30 12:53:19 +04:00
|
|
|
|
2018-01-03 13:23:14 +03:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2014-05-30 12:53:19 +04:00
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2018-06-02 17:29:21 +03:00
|
|
|
#include "base/flat_set.h"
|
2017-10-27 18:37:27 +03:00
|
|
|
|
2021-03-12 16:48:00 +04:00
|
|
|
namespace MTP {
|
|
|
|
|
|
|
|
class Error {
|
2014-05-30 12:53:19 +04:00
|
|
|
public:
|
2021-03-12 16:48:00 +04:00
|
|
|
explicit Error(const MTPrpcError &error);
|
|
|
|
explicit Error(const mtpBuffer &reply);
|
2014-05-30 12:53:19 +04:00
|
|
|
|
|
|
|
enum {
|
|
|
|
NoError,
|
|
|
|
TimeoutError
|
|
|
|
};
|
|
|
|
|
2021-03-12 14:45:13 +04:00
|
|
|
[[nodiscard]] int32 code() const;
|
|
|
|
[[nodiscard]] const QString &type() const;
|
|
|
|
[[nodiscard]] const QString &description() const;
|
|
|
|
|
2021-03-12 16:48:00 +04:00
|
|
|
[[nodiscard]] static Error Local(
|
2021-03-12 14:45:13 +04:00
|
|
|
const QString &type,
|
|
|
|
const QString &description);
|
|
|
|
[[nodiscard]] static MTPrpcError MTPLocal(
|
|
|
|
const QString &type,
|
|
|
|
const QString &description);
|
2014-05-30 12:53:19 +04:00
|
|
|
|
2019-01-13 17:28:05 +04:00
|
|
|
private:
|
2021-03-12 14:45:13 +04:00
|
|
|
int32 _code = 0;
|
2014-05-30 12:53:19 +04:00
|
|
|
QString _type, _description;
|
2019-01-13 17:28:05 +04:00
|
|
|
|
2014-05-30 12:53:19 +04:00
|
|
|
};
|
|
|
|
|
2021-03-31 21:15:49 +04:00
|
|
|
inline bool IsFloodError(const QString &type) {
|
2024-03-28 13:46:30 +04:00
|
|
|
return type.startsWith(u"FLOOD_WAIT_"_q)
|
|
|
|
|| type.startsWith(u"FLOOD_PREMIUM_WAIT_"_q);
|
2021-03-31 21:15:49 +04:00
|
|
|
}
|
|
|
|
|
2021-03-12 16:48:00 +04:00
|
|
|
inline bool IsFloodError(const Error &error) {
|
2021-03-31 21:15:49 +04:00
|
|
|
return IsFloodError(error.type());
|
2016-04-08 14:44:35 +04:00
|
|
|
}
|
|
|
|
|
2021-03-12 16:48:00 +04:00
|
|
|
inline bool IsTemporaryError(const Error &error) {
|
|
|
|
return error.code() < 0 || error.code() >= 500 || IsFloodError(error);
|
2015-04-04 23:01:34 +03:00
|
|
|
}
|
|
|
|
|
2021-03-12 16:48:00 +04:00
|
|
|
inline bool IsDefaultHandledError(const Error &error) {
|
|
|
|
return IsTemporaryError(error);
|
2016-04-08 14:44:35 +04:00
|
|
|
}
|
|
|
|
|
2021-03-12 14:45:13 +04:00
|
|
|
struct Response {
|
|
|
|
mtpBuffer reply;
|
|
|
|
mtpMsgId outerMsgId = 0;
|
2019-11-15 16:04:32 +03:00
|
|
|
mtpRequestId requestId = 0;
|
2014-05-30 12:53:19 +04:00
|
|
|
};
|
2017-03-09 22:15:31 +03:00
|
|
|
|
2021-03-12 14:45:13 +04:00
|
|
|
using DoneHandler = FnMut<bool(const Response&)>;
|
2021-03-12 16:48:00 +04:00
|
|
|
using FailHandler = Fn<bool(const Error&, const Response&)>;
|
2016-10-05 19:56:27 +03:00
|
|
|
|
2021-03-12 14:45:13 +04:00
|
|
|
struct ResponseHandler {
|
|
|
|
DoneHandler done;
|
|
|
|
FailHandler fail;
|
2016-10-05 19:56:27 +03:00
|
|
|
};
|
|
|
|
|
2021-03-12 14:45:13 +04:00
|
|
|
} // namespace MTP
|