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(const QString &sender, const QString &receiver, ServerErrorCode errorCode,
13  const QString &causingParameter, const QString &description)
14  : MessageBase(sender, receiver), m_errorNumber(errorCode), m_causingParameter(causingParameter),
15  m_description(description)
16  {}
17 
19  {
20  static const QVector<ServerErrorCode> fatalErrors {
21  ServerErrorCode::CallsignInUse, ServerErrorCode::InvalidCallsign,
22  ServerErrorCode::AlreadyRegistered, ServerErrorCode::InvalidCidPassword,
23  ServerErrorCode::InvalidRevision, ServerErrorCode::RequestedLevelTooHigh,
24  ServerErrorCode::ServerFull, ServerErrorCode::CidSuspended,
25  ServerErrorCode::RatingTooLow, ServerErrorCode::InvalidClient,
26  ServerErrorCode::AuthTimeout,
27  };
28 
29  return fatalErrors.contains(m_errorNumber);
30  }
31 
33  {
34  auto tokens = QStringList {};
35  tokens.push_back(m_sender);
36  tokens.push_back(m_receiver);
37  tokens.push_back(QString::number(static_cast<int>(m_errorNumber)));
38  tokens.push_back(m_causingParameter);
39  tokens.push_back(m_description);
40  return tokens;
41  }
42 
44  {
45  if (tokens.size() < 5)
46  {
47  swift::misc::CLogMessage(static_cast<ServerError *>(nullptr)).debug(u"Wrong number of arguments.");
48  return {};
49  }
50  return { tokens[0], tokens[1], static_cast<ServerErrorCode>(tokens[2].toInt()), tokens[3], tokens[4] };
51  }
52 } // 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:43
QStringList toTokens() const
Message converted to tokens.
Definition: servererror.cpp:32
bool isFatalError() const
Fatal?
Definition: servererror.cpp:18
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
bool contains(const AT &value) const const
void push_back(QList< T >::parameter_type value)
qsizetype size() const const
QString number(double n, char format, int precision)