Added code to deal with improperly formatted codes

This commit is contained in:
2024-02-11 23:23:00 -05:00
parent c8bc17fbce
commit 4378aa3c6a

View File

@@ -63,6 +63,9 @@ namespace connect_code {
/* Given a code, decode it and return a vector with the address and port */
std::vector<std::string> decode(std::string connect_code) {
if (connect_code.find("_") == std::string::npos) {
throw std::invalid_argument("Invalid code entered.");
}
std::vector<std::string> result = tokenize_str(connect_code, "_"); /* Split the string into address and port */
std::string address = result[0]; /* Address (in base 16) */
std::string port = result[1]; /* Port (in base 16) */
@@ -80,5 +83,4 @@ namespace connect_code {
return ret_val;
}
}