Audacity 3.2.0
CloudSyncError.cpp
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*!********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 CloudSyncError.cpp
7
8 Dmitry Vedenko
9
10**********************************************************************/
11#include "CloudSyncError.h"
12
13#include <unordered_map>
14
15#include "IResponse.h"
16
17#include "CodeConversions.h"
18#include "TranslatableString.h"
19
21{
22CLOUD_AUDIOCOM_API CloudSyncError
24{
25 using namespace audacity::network_manager;
26
27 const auto error = response.getError();
28
29 if (error == NetworkError::NoError)
30 return {};
31
32 CloudSyncError result;
33
34 if (error != NetworkError::HTTPError)
35 {
36 result.Type = error == NetworkError::OperationCancelled ?
39
40 result.ErrorMessage = response.getErrorString();
41
42 return result;
43 }
44
45 const auto statusCode = response.getHTTPCode();
46
47 static const std::unordered_map<int, CloudSyncError::ErrorType> errors {
60 };
61
62 const auto it = errors.find(statusCode);
63
64 result.Type = it == errors.end() ? CloudSyncError::Server : it->second;
65
66 result.ErrorMessage = std::string("HTTP ") + std::to_string(statusCode) +
67 std::string("\n") + response.readAll<std::string>();
68
69 return result;
70}
71
73{
75 audacity::ToUTF8(message.Translation()) };
76}
77
78CloudSyncError MakeClientFailure(const std::string& message)
79{
80 return { CloudSyncError::ClientFailure, message };
81}
82
84{
85 return { CloudSyncError::ClientFailure, message };
86}
87
89{
90 switch (code)
91 {
118 }
119
121}
122
123} // namespace audacity::cloud::audiocom::sync
Declare functions to perform UTF-8 to std::wstring conversions.
Declare an interface for HTTP response.
Holds a msgid for the translation catalog; may also bind format arguments.
wxString Translation() const
Interface, that provides access to the data from the HTTP response.
Definition: IResponse.h:113
virtual std::string getErrorString() const =0
virtual unsigned getHTTPCode() const noexcept=0
virtual NetworkError getError() const noexcept=0
CloudSyncError::ErrorType DeduceError(SyncResultCode code)
CloudSyncError MakeClientFailure(const TranslatableString &message)
CLOUD_AUDIOCOM_API CloudSyncError DeduceUploadError(audacity::network_manager::IResponse &response)
std::string ToUTF8(const std::wstring &wstr)