magpie/API/codes.cpp

34 lines
1.1 KiB
C++

#include "codes.h"
#include <iostream>
constexpr std::array<const char*, uint8_t(Codes::Register::unknownError) + 1> registerErrors({
"Successfully registered an account",
"Login have not been provided",
"The login can not be empty",
"User with provided login already exists",
"Provided login doesn't comply with server policies",
"Password have not been provided",
"Password can not be empty",
"Provided password doesn't comply with server policies",
"Unknown registration error"
});
Codes::Register Codes::convertRegister (int source) {
if (source < 0) {
std::cerr << "Converting Register response code which is smaller than zero, falling back to unknownError" << std::endl;
return Register::unknownError;
}
if (source > (int)Register::unknownError) {
std::cerr << "Converting Register response code which is bigger than biggest known, falling back to unknownError" << std::endl;
return Register::unknownError;
}
return static_cast<Register>(source);
}
QString Codes::description(Register code) {
return registerErrors[(uint8_t)code];
}