swift
servererror.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2019 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
4 #include "core/fsd/servererror.h"
5 
6 #include <QVector>
7 
8 #include "misc/logmessage.h"
9 
10 namespace swift::core::fsd
11 {
12  ServerError::ServerError() {}
13 
14  ServerError::ServerError(const QString &sender, const QString &receiver, ServerErrorCode errorCode,
15  const QString &causingParameter, const QString &description)
16  : MessageBase(sender, receiver), m_errorNumber(errorCode), m_causingParameter(causingParameter),
17  m_description(description)
18  {}
19 
21  {
22  static const QVector<ServerErrorCode> fatalErrors {
23  ServerErrorCode::CallsignInUse, ServerErrorCode::InvalidCallsign,
24  ServerErrorCode::AlreadyRegistered, ServerErrorCode::InvalidCidPassword,
25  ServerErrorCode::InvalidRevision, ServerErrorCode::RequestedLevelTooHigh,
26  ServerErrorCode::ServerFull, ServerErrorCode::CidSuspended,
27  ServerErrorCode::RatingTooLow, ServerErrorCode::InvalidClient,
28  ServerErrorCode::AuthTimeout,
29  };
30 
31  if (fatalErrors.contains(m_errorNumber)) { return true; }
32  else { return false; }
33  }
34 
35  QStringList ServerError::toTokens() const
36  {
37  auto tokens = QStringList {};
38  tokens.push_back(m_sender);
39  tokens.push_back(m_receiver);
40  tokens.push_back(QString::number(static_cast<int>(m_errorNumber)));
41  tokens.push_back(m_causingParameter);
42  tokens.push_back(m_description);
43  return tokens;
44  }
45 
46  ServerError ServerError::fromTokens(const QStringList &tokens)
47  {
48  if (tokens.size() < 5)
49  {
50  swift::misc::CLogMessage(static_cast<ServerError *>(nullptr)).debug(u"Wrong number of arguments.");
51  return {};
52  }
53  return ServerError(tokens[0], tokens[1], static_cast<ServerErrorCode>(tokens[2].toInt()), tokens[3], tokens[4]);
54  }
55 } // namespace swift::core::fsd
FSD message base class.
Definition: messagebase.h:58
QString m_receiver
message receiver
Definition: messagebase.h:89
QString m_sender
message sender
Definition: messagebase.h:88
FSD Message Server Error.
Definition: servererror.h:16
QString m_description
Properties.
Definition: servererror.h:52
static ServerError fromTokens(const QStringList &tokens)
Construct from tokens.
Definition: servererror.cpp:46
QStringList toTokens() const
Message converted to tokens.
Definition: servererror.cpp:35
bool isFatalError() const
Fatal?
Definition: servererror.cpp:20
QString m_causingParameter
Properties.
Definition: servererror.h:51
ServerErrorCode m_errorNumber
Properties.
Definition: servererror.h:50
Class for emitting a log message.
Definition: logmessage.h:27
Derived & debug()
Set the severity to debug.
ServerErrorCode
Server error codes.
Definition: enums.h:99