mirror of
https://github.com/ading2210/libcurl.js.git
synced 2025-05-13 14:30:02 -04:00
fix error handling
This commit is contained in:
parent
b9b871b25a
commit
a6f190fcda
3 changed files with 16 additions and 7 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -81,8 +81,12 @@ function perform_request(url, params, js_data_callback, js_end_callback, js_head
|
|||
_free(url_ptr);
|
||||
_free(response_json_ptr);
|
||||
|
||||
//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");
|
||||
headers_callback_ptr = Module.addFunction(headers_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;
|
||||
}
|
||||
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);
|
||||
|
|
|
@ -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": {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue