tdesktop/Telegram/SourceFiles/mtproto/mtproto_response.h

72 lines
1.5 KiB
C
Raw Normal View History

/*
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
*/
#pragma once
2018-06-02 14:29:21 +00:00
#include "base/flat_set.h"
2021-03-12 12:48:00 +00:00
namespace MTP {
class Error {
public:
2021-03-12 12:48:00 +00:00
explicit Error(const MTPrpcError &error);
explicit Error(const mtpBuffer &reply);
enum {
NoError,
TimeoutError
};
[[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(
const QString &type,
const QString &description);
[[nodiscard]] static MTPrpcError MTPLocal(
const QString &type,
const QString &description);
2019-01-13 13:28:05 +00:00
private:
int32 _code = 0;
QString _type, _description;
2019-01-13 13:28:05 +00:00
};
inline bool IsFloodError(const QString &type) {
return type.startsWith(qstr("FLOOD_WAIT_"));
}
2021-03-12 12:48:00 +00:00
inline bool IsFloodError(const Error &error) {
return IsFloodError(error.type());
}
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);
}
struct Response {
mtpBuffer reply;
mtpMsgId outerMsgId = 0;
mtpRequestId requestId = 0;
};
using DoneHandler = FnMut<bool(const Response&)>;
2021-03-12 12:48:00 +00:00
using FailHandler = Fn<bool(const Error&, const Response&)>;
struct ResponseHandler {
DoneHandler done;
FailHandler fail;
};
} // namespace MTP