Debian Codegraph @

mtxclient/include/mtx/lightweight_error.hpp

raw symbols SCIP
1 #pragma once
2
3 /// @file
4 /// @brief Error codes returned by the Matrix API.
5
6 #if __has_include(<nlohmann/json_fwd.hpp>)
7 #include <nlohmann/json_fwd.hpp>
8 #else
9 #include <nlohmann/json.hpp>
10 #endif
11 #include <string>
12
13 namespace mtx {
14 //! Namespace for Matrix errors.
15 namespace errors {
16
17 //! A Matrix error code.
18 enum class ErrorCode
19 {
20 M_UNRECOGNIZED,
21 //! unknown user or so
22 M_UNKNOWN,
23 //! Forbidden access, e.g. joining a room without permission, failed login.
24 M_FORBIDDEN,
25 //! The access token specified was not recognised.
26 M_UNKNOWN_TOKEN,
27 //! Request contained valid JSON, but it was malformed in some way,
28 //! e.g. missing required keys, invalid values for keys
29 M_BAD_JSON,
30 //! Request did not contain valid JSON.
31 M_NOT_JSON,
32 //! No resource was found for this request.
33 M_NOT_FOUND,
34 //! Too many requests have been sent in a short period of time.
35 M_LIMIT_EXCEEDED,
36 //! Encountered when trying to register a user ID which has been taken.
37 M_USER_IN_USE,
38 //! Encountered when trying to register a user ID which is not valid.
39 M_INVALID_USERNAME,
40 //! Sent when the room alias given to the createRoom API is already in use.
41 M_ROOM_IN_USE,
42 //! Sent when the intial state given to the createRoom API is invalid.
43 M_INVALID_ROOM_STATE,
44 //! Encountered when specifying bad pagination query parameters.
45 M_BAD_PAGINATION,
46 //! Sent when a threepid given to an API cannot be used because
47 //! the same threepid is already in use.
48 M_THREEPID_IN_USE,
49 //! Sent when a threepid given to an API cannot be used
50 //! because no record matching the threepid was found.
51 M_THREEPID_NOT_FOUND,
52 //! The client's request used a third party server,
53 //! eg. ID server, that this server does not trust.
54 M_SERVER_NOT_TRUSTED,
55 //! The access token isn't present in the request.
56 M_MISSING_TOKEN,
57 //! One of the uploaded signatures was invalid
58 M_INVALID_SIGNATURE,
59 //! The resource being requested is reserved by an application service, or the application
60 //! service making the request has not created the resource.
61 M_EXCLUSIVE,
62 };
63
64 //! Convert an error code into a string.
65 std::string
66 to_string(ErrorCode code);
67
68 //! Parse an error code from a string.
69 ErrorCode
70 from_string(const std::string &code);
71
72 //! Represents a Matrix related error.
73 struct LightweightError
74 {
75 //! Error code.
76 ErrorCode errcode = {};
77 //! Human readable version of the error.
78 std::string error;
79
80 friend void from_json(const nlohmann::json &obj, LightweightError &error);
81 };
82 }
83 }