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
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
2018-06-02 14:29:21 +00:00
|
|
|
#include "base/flat_set.h"
|
2017-10-27 15:37:27 +00:00
|
|
|
|
2021-03-12 12:48:00 +00:00
|
|
|
namespace MTP {
|
|
|
|
|
|
|
|
class Error {
|
2014-05-30 08:53:19 +00:00
|
|
|
public:
|
2021-03-12 12:48:00 +00:00
|
|
|
explicit Error(const MTPrpcError &error);
|
|
|
|
explicit Error(const mtpBuffer &reply);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
NoError,
|
|
|
|
TimeoutError
|
|
|
|
};
|
|
|
|
|
2021-03-12 10:45:13 +00:00
|
|
|
[[nodiscard]] int32 code() const;
|
|
|
|
[[nodiscard]] const QString &type() const;
|
|
|
|
[[nodiscard]] const QString &description() const;
|
|
|
|
|
2021-03-12 12:48:00 +00:00
|
|
|
[[nodiscard]] static Error Local(
|
2021-03-12 10:45:13 +00:00
|
|
|
const QString &type,
|
|
|
|
const QString &description);
|
|
|
|
[[nodiscard]] static MTPrpcError MTPLocal(
|
|
|
|
const QString &type,
|
|
|
|
const QString &description);
|
2014-05-30 08:53:19 +00:00
|
|
|
|
2019-01-13 13:28:05 +00:00
|
|
|
private:
|
2021-03-12 10:45:13 +00:00
|
|
|
int32 _code = 0;
|
2014-05-30 08:53:19 +00:00
|
|
|
QString _type, _description;
|
2019-01-13 13:28:05 +00:00
|
|
|
|
2014-05-30 08:53:19 +00:00
|
|
|
};
|
|
|
|
|
2021-03-31 17:15:49 +00:00
|
|
|
inline bool IsFloodError(const QString &type) {
|
2022-11-26 21:20:17 +00:00
|
|
|
return type.startsWith(u"FLOOD_WAIT_"_q);
|
2021-03-31 17:15:49 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:48:00 +00:00
|
|
|
inline bool IsFloodError(const Error &error) {
|
2021-03-31 17:15:49 +00:00
|
|
|
return IsFloodError(error.type());
|
2016-04-08 10:44:35 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:48:00 +00:00
|
|
|
inline bool IsTemporaryError(const Error &error) {
|
|
|
|
return error.code() < 0 || error.code() >= 500 || IsFloodError(error);
|
2015-04-04 20:01:34 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 12:48:00 +00:00
|
|
|
inline bool IsDefaultHandledError(const Error &error) {
|
|
|
|
return IsTemporaryError(error);
|
2016-04-08 10:44:35 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 10:45:13 +00:00
|
|
|
struct Response {
|
|
|
|
mtpBuffer reply;
|
|
|
|
mtpMsgId outerMsgId = 0;
|
2019-11-15 13:04:32 +00:00
|
|
|
mtpRequestId requestId = 0;
|
2014-05-30 08:53:19 +00:00
|
|
|
};
|
2017-03-09 19:15:31 +00:00
|
|
|
|
2021-03-12 10:45:13 +00:00
|
|
|
using DoneHandler = FnMut<bool(const Response&)>;
|
2021-03-12 12:48:00 +00:00
|
|
|
using FailHandler = Fn<bool(const Error&, const Response&)>;
|
2016-10-05 16:56:27 +00:00
|
|
|
|
2021-03-12 10:45:13 +00:00
|
|
|
struct ResponseHandler {
|
|
|
|
DoneHandler done;
|
|
|
|
FailHandler fail;
|
2016-10-05 16:56:27 +00:00
|
|
|
};
|
|
|
|
|
2021-03-12 10:45:13 +00:00
|
|
|
} // namespace MTP
|