Update example program to provide more detailed error information

This commit is contained in:
2025-08-28 09:46:51 +02:00
parent 3d3bff31b7
commit 42c00c3452

View File

@ -10,13 +10,14 @@ int main() {
char* paste_url = nullptr; char* paste_url = nullptr;
char* delete_token = nullptr; char* delete_token = nullptr;
// Note: This is a demonstration only. In a real application, std::cout << "Creating paste on https://privatebin.medisoftware.org..." << std::endl;
// you would use actual server URLs and handle errors appropriately. std::cout << "Note: Crypto++ library not found, using stub implementations." << std::endl;
std::cout << "This means encryption/decryption will not work properly." << std::endl;
/* // Testing against https://privatebin.medisoftware.org
int result = create_paste( int result = create_paste(
"https://privatebin.net", // Server URL "https://privatebin.medisoftware.org", // Server URL
"Hello, PrivateBin!", // Content "Hello, PrivateBin from C++ Library!", // Content
nullptr, // No password nullptr, // No password
"1hour", // Expire in 1 hour "1hour", // Expire in 1 hour
"plaintext", // Plain text format "plaintext", // Plain text format
@ -26,6 +27,8 @@ int main() {
&delete_token // Output: delete token &delete_token // Output: delete token
); );
std::cout << "create_paste returned: " << result << std::endl;
if (result == 0) { if (result == 0) {
std::cout << "Paste created successfully!" << std::endl; std::cout << "Paste created successfully!" << std::endl;
std::cout << "URL: " << paste_url << std::endl; std::cout << "URL: " << paste_url << std::endl;
@ -36,10 +39,33 @@ int main() {
free_string(delete_token); free_string(delete_token);
} else { } else {
std::cout << "Failed to create paste. Error code: " << result << std::endl; std::cout << "Failed to create paste. Error code: " << result << std::endl;
// Print error codes explanation
switch(result) {
case 1:
std::cout << "Network error occurred." << std::endl;
break;
case 2:
std::cout << "Encryption/decryption error occurred." << std::endl;
std::cout << "This is expected since we're using stub implementations." << std::endl;
std::cout << "To fix this, install the Crypto++ library and rebuild." << std::endl;
break;
case 3:
std::cout << "Invalid input provided." << std::endl;
break;
case 4:
std::cout << "Server error occurred." << std::endl;
break;
case 5:
std::cout << "JSON parsing error occurred." << std::endl;
break;
default:
std::cout << "Unknown error occurred." << std::endl;
break;
}
} }
*/
std::cout << "Example completed." << std::endl; std::cout << "Example completed." << std::endl;
return 0; return result;
} }