diff options
author | bptato <nincsnevem662@gmail.com> | 2023-06-19 20:16:39 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2023-06-19 20:17:06 +0200 |
commit | 82fb1f70ab275884c42dd769b2af8f9df5389e88 (patch) | |
tree | b7a83ca2e2d22e926959f2525169f2a2e4530e38 /src/io/request.nim | |
parent | 070cfca46f60c3a00fe6dd66457f454a1a217897 (diff) | |
download | chawan-82fb1f70ab275884c42dd769b2af8f9df5389e88.tar.gz |
Get rid of the .jserr pragma
Diffstat (limited to 'src/io/request.nim')
-rw-r--r-- | src/io/request.nim | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/io/request.nim b/src/io/request.nim index 8bc2bfc8..86c8a38d 100644 --- a/src/io/request.nim +++ b/src/io/request.nim @@ -4,6 +4,7 @@ import strutils import tables import bindings/quickjs +import js/exception import js/javascript import types/formdata import types/url @@ -225,13 +226,10 @@ func createPotentialCORSRequest*(url: URL, destination: RequestDestination, cors #TODO resource as Request #TODO init as an actual dictionary func newRequest*(ctx: JSContext, resource: string, - init = none(JSValue)): Request {.jserr, jsctor.} = - let x = parseURL(resource) - if x.isNone: - JS_ERR JS_TypeError, resource & " is not a valid URL." - if x.get.username != "" or x.get.password != "": - JS_ERR JS_TypeError, resource & " is not a valid URL." - let url = x.get + init = none(JSValue)): Result[Request, JSError] {.jsctor.} = + let url = ?newURL(resource) + if url.username != "" or url.password != "": + return err(newTypeError("Input URL contains a username or password")) let fallbackMode = some(RequestMode.CORS) #TODO none if resource is request var httpMethod = HTTP_GET var body = opt(string) @@ -254,7 +252,7 @@ func newRequest*(ctx: JSContext, resource: string, #TODO inputbody if (multipart.isSome or body.isSome) and httpMethod in {HTTP_GET, HTTP_HEAD}: - JS_ERR JS_TypeError, "HEAD or GET Request cannot have a body." + return err(newTypeError("HEAD or GET Request cannot have a body.")) let jheaders = JS_GetPropertyStr(ctx, init, "headers") hl.fill(ctx, jheaders) credentials = fromJS[CredentialsMode](ctx, JS_GetPropertyStr(ctx, init, @@ -263,8 +261,8 @@ func newRequest*(ctx: JSContext, resource: string, .get(mode) #TODO find a standard compatible way to implement this proxyUrl = fromJS[URL](ctx, JS_GetPropertyStr(ctx, init, "proxyUrl")) - return newRequest(url, httpMethod, hl, body, multipart, mode, credentials, - proxy = proxyUrl.get(nil)) + return ok(newRequest(url, httpMethod, hl, body, multipart, mode, credentials, + proxy = proxyUrl.get(nil))) proc add*(headers: var Headers, k, v: string) = let k = k.toHeaderCase() |