throw error objects instead of plain strings, update wisp server

This commit is contained in:
ading2210 2024-10-02 12:30:48 -04:00
parent 3c1a942501
commit c1b78e1d0c
11 changed files with 16 additions and 15 deletions

View file

@ -1,5 +1,9 @@
# Libcurl.js Changelog: # Libcurl.js Changelog:
## v0.6.16 (10/2/24):
- Fix a bug with `Headers` objects and `Request` objects not being properly handled when passed into `libcurl.fetch`
- Errors thrown are now `Error` or `TypeError` objects instead of plain strings
## v0.6.15 (9/6/24): ## v0.6.15 (9/6/24):
- WolfSSL has been downgraded to v5.6.6 due to an upstream regression - WolfSSL has been downgraded to v5.6.6 due to an upstream regression

View file

@ -9,7 +9,7 @@ try {
ws = new WebSocket(url); ws = new WebSocket(url);
} }
else if (typeof api.transport === "string") { else if (typeof api.transport === "string") {
throw "invalid transport type"; throw new TypeError("invalid transport type");
} }
else { //custom transports else { //custom transports
ws = new api.transport(url); ws = new api.transport(url);

View file

@ -67,13 +67,13 @@ class HTTPSession extends CurlSession {
} }
if (error > 0) { if (error > 0) {
error_msg(`Request "${url}" failed with error code ${error}: ${get_error_str(error)}`); error_msg(`Request "${url}" failed with error code ${error}: ${get_error_str(error)}`);
reject(`Request failed with error code ${error}: ${get_error_str(error)}`); reject(new TypeError(`Request failed with error code ${error}: ${get_error_str(error)}`));
} }
else if (error === -1) { else if (error === -1) {
reject(new DOMException("The operation was aborted.")); reject(new DOMException("The operation was aborted."));
} }
else if (error === -2) { else if (error === -2) {
reject("Request failed because redirects were disallowed."); reject(new TypeError("Request failed because redirects were disallowed."));
} }
this.remove_request(http_handle); this.remove_request(http_handle);
http_handle = null; http_handle = null;

View file

@ -139,7 +139,7 @@ api = {
CurlWebSocket: CurlWebSocket, CurlWebSocket: CurlWebSocket,
TLSSocket: TLSSocket, TLSSocket: TLSSocket,
HTTPSession: HTTPSession, HTTPSession: HTTPSession,
fetch() {throw "not ready"}, fetch() {throw new Error("not ready")},
get copyright() {return copyright_notice}, get copyright() {return copyright_notice},
get version() {return get_version()}, get version() {return get_version()},

View file

@ -24,7 +24,7 @@ class CurlSession {
assert_ready() { assert_ready() {
if (!this.session_ptr) { if (!this.session_ptr) {
throw "session has been removed"; throw new Error("session has been removed");
} }
} }

View file

@ -70,7 +70,7 @@ function data_to_array(data) {
return new Uint8Array(data.buffer); return new Uint8Array(data.buffer);
} }
throw "invalid data type to be sent"; throw new TypeError("invalid data type to be sent");
} }
//c function wrapper //c function wrapper

View file

@ -62,7 +62,7 @@ class FakeWebSocket extends EventTarget {
converted = data.buffer; converted = data.buffer;
} }
else { else {
throw "invalid binaryType string"; throw new TypeError("invalid binaryType string");
} }
} }

View file

@ -1,15 +1,12 @@
{ {
"name": "libcurl.js", "name": "libcurl.js",
"version": "0.6.15", "version": "0.6.16",
"description": "An experimental port of libcurl to WebAssembly for use in the browser.", "description": "A port of libcurl to WebAssembly, for proxying HTTPS requests from the browser with full TLS encryption",
"main": "libcurl.mjs", "main": "libcurl.mjs",
"exports": { "exports": {
".": "./libcurl.mjs", ".": "./libcurl.mjs",
"./bundled": "./libcurl_full.mjs" "./bundled": "./libcurl_full.mjs"
}, },
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/ading2210/libcurl.js.git" "url": "git+https://github.com/ading2210/libcurl.js.git"

View file

@ -4,7 +4,7 @@ set -e
trap "exit" INT TERM trap "exit" INT TERM
trap "kill 0" EXIT trap "kill 0" EXIT
../server/run.sh --static=$(pwd) >/dev/null & ../server/run.sh --static=$(pwd) --log-level=WARN >/dev/null &
echo -n "waiting for wisp server to start" echo -n "waiting for wisp server to start"
i=0 i=0

View file

@ -13,7 +13,7 @@ if [ ! -d "$SERVER_PATH.venv" ]; then
fi fi
source $SERVER_PATH/.venv/bin/activate source $SERVER_PATH/.venv/bin/activate
if ! python3 -c "import websockets, asyncudp" 2> /dev/null; then if ! python3 -c "import websockets, asyncudp, uvloop" 2> /dev/null; then
pip3 install -e $SERVER_PATH pip3 install -e $SERVER_PATH
fi fi

@ -1 +1 @@
Subproject commit b7cfab072b04dbd4345aedaf5e47c9e0d57ab873 Subproject commit 78f872c8e5b180e26ec09cc126e841e12ac75c36