Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2021 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 :
23 : #ifndef MUSE_CLOUD_CLOUDERRORS_H
24 : #define MUSE_CLOUD_CLOUDERRORS_H
25 :
26 : #include "types/ret.h"
27 :
28 : namespace muse::cloud {
29 : static const std::string CLOUD_NETWORK_ERROR_USER_DESCRIPTION_KEY("userDescription");
30 :
31 : enum class Err {
32 : Undefined = int(Ret::Code::Undefined),
33 : NoError = int(Ret::Code::Ok),
34 : UnknownError = int(Ret::Code::CloudFirst),
35 :
36 : AccessTokenIsEmpty,
37 : InvalidData,
38 : Status400_InvalidRequest,
39 : Status401_AuthorizationRequired,
40 : Status403_AccountNotActivated,
41 : Status403_NotOwner,
42 : Status404_NotFound,
43 : Status409_Conflict,
44 : Status422_ValidationFailed,
45 : Status429_RateLimitExceeded,
46 : Status500_InternalServerError,
47 : UnknownStatusCode,
48 : NetworkError,
49 : CouldNotReceiveSourceUrl,
50 : };
51 :
52 51 : inline Ret make_ret(Err e)
53 : {
54 51 : int retCode = static_cast<int>(e);
55 :
56 51 : switch (e) {
57 0 : case Err::Undefined: return Ret(retCode);
58 0 : case Err::NoError: return Ret(retCode);
59 2 : case Err::UnknownError: return Ret(retCode);
60 15 : case Err::AccessTokenIsEmpty: return Ret(retCode, "Access token is empty");
61 0 : case Err::InvalidData: return Ret(retCode, "Invalid data");
62 6 : case Err::Status400_InvalidRequest: return Ret(retCode, "Status 400: invalid request");
63 9 : case Err::Status401_AuthorizationRequired: return Ret(retCode, "Status 401: authorization required");
64 3 : case Err::Status403_AccountNotActivated: return Ret(retCode, "Status 403: account not activated");
65 6 : case Err::Status403_NotOwner: return Ret(retCode, "Status 403: not owner");
66 9 : case Err::Status404_NotFound: return Ret(retCode, "Status 404: not found");
67 9 : case Err::Status409_Conflict: return Ret(retCode, "Status 409: conflict");
68 6 : case Err::Status422_ValidationFailed: return Ret(retCode, "Status 422: validation failed");
69 3 : case Err::Status429_RateLimitExceeded: return Ret(retCode, "Status 429: rate limit exceeded");
70 6 : case Err::Status500_InternalServerError: return Ret(retCode, "Status 500: internal server error");
71 3 : case Err::UnknownStatusCode: return Ret(retCode, "Unknown status code");
72 69 : case Err::NetworkError: return Ret(retCode, "Network error");
73 3 : case Err::CouldNotReceiveSourceUrl: return Ret(retCode, "Could not receive source url");
74 : break;
75 : }
76 :
77 0 : return Ret(retCode);
78 : }
79 : }
80 :
81 : #endif // MUSE_CLOUD_CLOUDERRORS_H
|