about summary refs log tree commit diff stats
path: root/src/io
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-06-09 15:27:29 +0200
committerbptato <nincsnevem662@gmail.com>2023-06-09 15:27:29 +0200
commite8fa2217df7bacc58e88737f21752bbdf0f5562a (patch)
tree8fbec22f273f2cab5811b2f9b1dd5ea05496ef1a /src/io
parentb39e35e46773258cb103397b2372612308c22ae0 (diff)
downloadchawan-e8fa2217df7bacc58e88737f21752bbdf0f5562a.tar.gz
Show error messages, fix some fetch crashes
Diffstat (limited to 'src/io')
-rw-r--r--src/io/loader.nim7
-rw-r--r--src/io/request.nim2
2 files changed, 9 insertions, 0 deletions
diff --git a/src/io/loader.nim b/src/io/loader.nim
index 5ed270ca..34eb9b42 100644
--- a/src/io/loader.nim
+++ b/src/io/loader.nim
@@ -282,6 +282,8 @@ proc onConnected*(loader: FileLoader, fd: int) =
     loader.ongoing[fd] = response
     promise.resolve(response)
   else:
+    loader.unregisterFun(fd)
+    loader.unregistered.add(fd)
     #TODO: reject promise instead.
     let response = newResponse(res, request)
     promise.resolve(response)
@@ -308,3 +310,8 @@ proc quit*(loader: FileLoader) =
   let stream = connectSocketStream(loader.process)
   if stream != nil:
     stream.swrite(QUIT)
+
+func getLoaderErrorMessage*(code: int): string =
+  if code < 0:
+    return $ConnectErrorCode(code)
+  return $curl_easy_strerror(CURLcode(cint(code)))
diff --git a/src/io/request.nim b/src/io/request.nim
index ed38ad47..4a123a0b 100644
--- a/src/io/request.nim
+++ b/src/io/request.nim
@@ -326,6 +326,8 @@ proc Response_json(ctx: JSContext, this: JSValue, argc: cint, argv: ptr JSValue)
     return JS_ThrowTypeError(ctx, "Value is not an instance of %s", "Response")
   let response = cast[Response](op)
   var s = response.text()
+  if s == "":
+    return JS_ThrowSyntaxError("unexpected end of input")
   return JS_ParseJSON(ctx, addr s[0], cast[csize_t](s.len), cstring"<input>")
 
 func credentialsMode*(attribute: CORSAttribute): CredentialsMode =