@@ -52,12 +52,23 @@ extern bool server_log_json;
52
52
#define LOG_WARNING (MSG, ...) server_log(" WARN" , __func__, __LINE__, MSG, __VA_ARGS__)
53
53
#define LOG_INFO ( MSG, ...) server_log(" INFO" , __func__, __LINE__, MSG, __VA_ARGS__)
54
54
55
+ static inline void server_log (const char *level, const char *function, int line, const char *message, const nlohmann::ordered_json &extra);
56
+
55
57
template <typename T>
56
58
static T json_value (const json &body, const std::string &key, const T &default_value) {
57
59
// Fallback null to default value
58
- return body.contains (key) && !body.at (key).is_null ()
59
- ? body.value (key, default_value)
60
- : default_value;
60
+ if (body.contains (key) && !body.at (key).is_null ()){
61
+ try {
62
+ return body.value (key, default_value);
63
+ }
64
+ catch (nlohmann::json_abi_v3_11_3::detail::type_error const &){
65
+ std::string message = " Wrong type supplied for parameter '" + key + " '. Expected '" + typeid (default_value).name () + " ', using default value." ;
66
+ server_log (" WARN" , __func__, __LINE__, message.c_str (), body);
67
+ return default_value;
68
+ }
69
+ } else {
70
+ return default_value;
71
+ }
61
72
}
62
73
63
74
static inline void server_log (const char *level, const char *function, int line, const char *message, const nlohmann::ordered_json &extra) {
0 commit comments