fix error handling

This commit is contained in:
ading2210 2024-03-11 01:20:42 -04:00
parent b9b871b25a
commit a6f190fcda
3 changed files with 16 additions and 7 deletions

View file

@ -1,5 +1,8 @@
# Libcurl.js Changelog:
## v0.5.2 (3/10/24):
- Fix a bug with error handling
## v0.5.1 (3/10/24):
- Added support for aborting requests

View file

@ -81,7 +81,11 @@ function perform_request(url, params, js_data_callback, js_end_callback, js_head
_free(url_ptr);
_free(response_json_ptr);
js_headers_callback(response_info);
//if the response status is 0, an error occurred,
//but we don't know what it is yet
if (response_info.status !== 0) {
js_headers_callback(response_info);
}
}
end_callback_ptr = Module.addFunction(end_callback, "vi");
@ -218,12 +222,14 @@ function perform_request_async(url, params, body) {
}
function finish_callback(error) {
if (error != 0) {
let error_str = `Request failed with error code ${error}: ${get_error_str(error)}`;
if (error != 0) error_msg(error_str);
reject(error_str);
error_msg(`Request "${url}" failed with error code ${error}: ${get_error_str(error)}`);
reject(`Request failed with error code ${error}: ${get_error_str(error)}`);
return;
}
stream_controller.close();
try {
stream_controller.close();
} //this will only fail if the stream is already errored or closed, which isn't a problem
catch {}
}
http_handle = perform_request(url, params, data_callback, finish_callback, headers_callback, body);

View file

@ -1,6 +1,6 @@
{
"name": "libcurl.js",
"version": "0.5.1",
"version": "0.5.2",
"description": "An experimental port of libcurl to WebAssembly for use in the browser.",
"main": "libcurl.mjs",
"scripts": {