Compare commits

...

3 Commits

Author SHA1 Message Date
Don Isaac
9eb2216a1d Merge branch 'main' into don/fix/confusing-fetch-err-message 2025-03-18 19:38:06 -07:00
Don Isaac
2af23f746f type fix 2025-03-17 14:45:20 -07:00
Don Isaac
1d50addacb fix(serve): make error messages for invalid fetch() clearer 2025-03-17 14:35:06 -07:00

View File

@@ -91,6 +91,8 @@ const ctxLog = Output.scoped(.RequestContext, false);
const S3 = bun.S3;
const SocketAddress = @import("bun/socket.zig").SocketAddress;
const bun_docs_url = "https://bun.sh/docs";
const BlobFileContentResult = struct {
data: [:0]const u8,
@@ -1674,7 +1676,16 @@ pub const ServerConfig = struct {
if (try arg.getTruthy(global, "fetch")) |onRequest_| {
if (!onRequest_.isCallable()) {
return global.throwInvalidArguments("Expected fetch() to be a function", .{});
if (onRequest_.isUndefined()) {
return global.throwInvalidArguments(
"Bun.serve() requires a fetch() function to handle incoming requests. For more information, see " ++ bun_docs_url ++ "api/http#bun-serve",
.{},
);
} else {
const ty = try global.determineSpecificType(onRequest_);
defer ty.deref();
return global.throwInvalidArguments("Expected 'fetch()' to be a function, got {s}", .{ty});
}
}
const onRequest = onRequest_.withAsyncContextIfNeeded(global);
JSC.C.JSValueProtect(global, onRequest.asObjectRef());