matt-42 / silicon

A high performance, middleware oriented C++14 http web framework please use matt-42/lithium instead
http://siliconframework.org
MIT License
1.72k stars 138 forks source link

double as post parameter throws ::boost::bad_lexical_cast #38

Closed fnc12 closed 7 years ago

fnc12 commented 7 years ago
POST / _product_in_stock * post_parameters(_product_id = int(),
                                          _price = double()) = [] (auto p) {
   cout << "price = " << p.price << endl;
}

Next implementing request: URL = http://192.168.1.10/product_in_stock Headers = Content-Type:application/json Method = POST Body:

{
    "product_id":1,
    "price":1.5
}

Exception is thrown:

libc++abi.dylib: terminating with uncaught exception of type boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector >: bad lexical cast: source type value could not be interpreted as target

vidcentum commented 7 years ago

I tried the above example. It ran successfully and printed "price = 1.5" on the console output.

tex commented 7 years ago

Does your locale use , as separator?

fnc12 commented 7 years ago

@tex I think yes. How to identify it? My OS is OS X , uname -a is Darwin Kernel Version 16.3.0

matt-42 commented 7 years ago

All json parsing errors are now catched by the MHD backend : https://github.com/matt-42/silicon/commit/e0616156290c36fc1cd9ddd21a0ef46a8de786d8 The parsing of number will still use your locale but at least it won't make the server crash anymore.