diff options
| author | 2022-09-16 22:50:46 -0700 | |
|---|---|---|
| committer | 2022-09-16 22:50:46 -0700 | |
| commit | 4b9f6baf7909cfb68335fd1effd40f0e593f36fb (patch) | |
| tree | 82930b28fefc8b6a575bb588026740e78e72fcf9 /src/bun.js | |
| parent | a675cbd13b5c3ea46dec2a734b3a96b53c0a8cfb (diff) | |
| download | bun-4b9f6baf7909cfb68335fd1effd40f0e593f36fb.tar.gz bun-4b9f6baf7909cfb68335fd1effd40f0e593f36fb.tar.zst bun-4b9f6baf7909cfb68335fd1effd40f0e593f36fb.zip | |
Make `fetch` throw a `SystemError` on reject
Diffstat (limited to 'src/bun.js')
| -rw-r--r-- | src/bun.js/webcore/response.zig | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/bun.js/webcore/response.zig b/src/bun.js/webcore/response.zig index 2ef8225f3..56d6fd5e3 100644 --- a/src/bun.js/webcore/response.zig +++ b/src/bun.js/webcore/response.zig @@ -583,15 +583,13 @@ pub const Fetch = struct { } pub fn onReject(this: *FetchTasklet) JSValue { - const fetch_error = std.fmt.allocPrint( - default_allocator, - "fetch() failed {s}\nurl: \"{s}\"", - .{ - this.result.fail, - this.result.href, - }, - ) catch unreachable; - return ZigString.init(fetch_error).toErrorInstance(this.global_this); + const fetch_error = JSC.SystemError{ + .code = ZigString.init(@errorName(this.result.fail)), + .message = ZigString.init("fetch() failed"), + .path = ZigString.init(this.http.?.url.href), + }; + + return fetch_error.toErrorInstance(this.global_this); } pub fn onResolve(this: *FetchTasklet) JSValue { |
