Make fetch throw a SystemError on reject

This commit is contained in:
Jarred Sumner
2022-09-16 22:50:46 -07:00
parent a675cbd13b
commit 4b9f6baf79
2 changed files with 8 additions and 9 deletions

View File

@@ -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 {

View File

@@ -1638,6 +1638,7 @@ pub fn handleResponseBodyChunk(
decoder.consume_trailer = 1;
var bytes_decoded = incoming_data.len;
// phr_decode_chunked mutates in-place
const pret = picohttp.phr_decode_chunked(
decoder,
buffer.list.items.ptr + (buffer.list.items.len - incoming_data.len),