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 : #ifndef MUSE_NETWORK_NETWORKERRORS_H
23 : #define MUSE_NETWORK_NETWORKERRORS_H
24 :
25 : #include "types/ret.h"
26 : #include "translation.h"
27 :
28 : namespace muse::network {
29 : enum class Err {
30 : Undefined = int(Ret::Code::Undefined),
31 : NoError = int(Ret::Code::Ok),
32 : UnknownError = int(Ret::Code::NetworkFirst),
33 :
34 : Abort,
35 : Timeout,
36 : NetworkError,
37 : FiledOpenIODeviceRead,
38 : FiledOpenIODeviceWrite
39 : };
40 :
41 20 : inline Ret make_ret(Err e)
42 : {
43 20 : int retCode = static_cast<int>(e);
44 :
45 20 : switch (e) {
46 0 : case Err::Undefined: return Ret(retCode);
47 0 : case Err::NoError: return Ret(retCode);
48 0 : case Err::UnknownError: return Ret(retCode);
49 0 : case Err::Abort: return Ret(retCode, muse::trc("network", "The request was aborted"));
50 0 : case Err::Timeout: return Ret(retCode, muse::trc("network", "The connection to the remote server timed out"));
51 19 : case Err::NetworkError: return Ret(retCode, muse::trc("network", "An unknown network-related error occurred"));
52 0 : case Err::FiledOpenIODeviceRead: return Ret(retCode, muse::trc("network", "The I/O device was not opened for reading"));
53 1 : case Err::FiledOpenIODeviceWrite: return Ret(retCode, muse::trc("network", "The I/O device was not opened for writing"));
54 : }
55 :
56 0 : return Ret(static_cast<int>(e));
57 : }
58 : }
59 :
60 : #endif // MUSE_NETWORK_NETWORKERRORS_H
|