Improved error handling of gta_data_service. (#411)

Fixed an issue where the game crashes when throwing invalid json format exception.
This commit is contained in:
aa15032261 2022-08-13 19:29:33 +08:00 committed by GitHub
parent 3c9f0dfcd9
commit 8faa090ffd
2 changed files with 17 additions and 16 deletions

View File

@ -59,16 +59,21 @@ namespace big::remote
http::Request req(file_url.data());
http::Response res = req.send("GET", "", headers, 30s);
std::ofstream file_ofstream(file_location, std::ios::binary | std::ios::trunc);
std::ostream_iterator<std::uint8_t> file_out_iter(file_ofstream);
std::copy(res.body.begin(), res.body.end(), file_out_iter);
if (res.status == http::Response::Status::Ok)
{
std::ofstream file_ofstream(file_location, std::ios::binary | std::ios::trunc);
std::ostream_iterator<std::uint8_t> file_out_iter(file_ofstream);
std::copy(res.body.begin(), res.body.end(), file_out_iter);
remote_etag = get_etag_from_headers(res.headers);
remote_etag = get_etag_from_headers(res.headers);
std::ofstream file_etag_ofstream(etag_location, std::ios::binary | std::ios::trunc);
file_etag_ofstream << remote_etag;
std::ofstream file_etag_ofstream(etag_location, std::ios::binary | std::ios::trunc);
file_etag_ofstream << remote_etag;
return true;
return true;
}
return false;
}
catch (const std::exception& e)
{

View File

@ -43,7 +43,6 @@ namespace big
g_gta_data_service = nullptr;
}
const vehicle_item& gta_data_service::find_vehicle_by_hash(Hash hash)
{
int idx = -1;
@ -168,11 +167,8 @@ namespace big
try
{
std::ofstream file_ofstream(file_path, std::ios::binary | std::ios::trunc);
file_ofstream << "";
std::ofstream file_etag_ofstream(etag_path, std::ios::binary | std::ios::trunc);
file_etag_ofstream << "";
std::filesystem::remove(file_to_load.get_path());
std::filesystem::remove(file_etag.get_path());
}
catch (...) { }
}
@ -197,7 +193,7 @@ namespace big
if (!all_vehicles.is_array())
{
throw "Invalid json format.";
throw std::exception("Invalid json format.");
}
m_vehicle_class_arr.clear();
@ -250,7 +246,7 @@ namespace big
if (!all_peds.is_array())
{
throw "Invalid json format.";
throw std::exception("Invalid json format.");
}
m_ped_type_arr.clear();
@ -301,7 +297,7 @@ namespace big
if (!all_weapons.is_array())
{
throw "Invalid json format.";
throw std::exception("Invalid json format.");
}
m_weapon_type_arr.clear();