fix error message in bun.serve (#8828)

* fix error message in bun.serve

* ok
This commit is contained in:
dave caruso
2024-02-09 17:24:46 -08:00
committed by GitHub
parent 90fd322b5c
commit dfcac563bc
3 changed files with 40 additions and 22 deletions

View File

@@ -861,28 +861,6 @@ pub const ServerConfig = struct {
}
}
if (arg.getTruthy(global, "tls")) |tls| {
if (SSLConfig.inJS(global, tls, exception)) |ssl_config| {
args.ssl_config = ssl_config;
}
if (exception.* != null) {
return args;
}
}
// @compatibility Bun v0.x - v0.2.1
// this used to be top-level, now it's "tls" object
if (args.ssl_config == null) {
if (SSLConfig.inJS(global, arg, exception)) |ssl_config| {
args.ssl_config = ssl_config;
}
if (exception.* != null) {
return args;
}
}
if (arg.getTruthy(global, "maxRequestBodySize")) |max_request_body_size| {
if (max_request_body_size.isNumber()) {
args.max_request_body_size = @as(u64, @intCast(@max(0, max_request_body_size.toInt64())));
@@ -917,6 +895,36 @@ pub const ServerConfig = struct {
}
return args;
}
if (arg.getTruthy(global, "tls")) |tls| {
if (SSLConfig.inJS(global, tls, exception)) |ssl_config| {
args.ssl_config = ssl_config;
}
if (exception.* != null) {
return args;
}
if (global.hasException()) {
return args;
}
}
// @compatibility Bun v0.x - v0.2.1
// this used to be top-level, now it's "tls" object
if (args.ssl_config == null) {
if (SSLConfig.inJS(global, arg, exception)) |ssl_config| {
args.ssl_config = ssl_config;
}
if (exception.* != null) {
return args;
}
if (global.hasException()) {
return args;
}
}
} else {
JSC.throwInvalidArguments("Bun.serve expects an object", .{}, global, exception);
return args;

View File

@@ -5351,3 +5351,8 @@ extern "C" EncodedJSValue ExpectStatic__getPrototype(JSC::JSGlobalObject* global
{
return JSValue::encode(reinterpret_cast<Zig::GlobalObject*>(globalObject)->JSExpectStaticPrototype());
}
extern "C" bool JSGlobalObject__hasException(JSC::JSGlobalObject* globalObject)
{
return DECLARE_CATCH_SCOPE(globalObject->vm()).exception() != 0;
}

View File

@@ -2922,6 +2922,11 @@ pub const JSGlobalObject = extern struct {
return cppFn("getCachedObject", .{ this, key });
}
extern fn JSGlobalObject__hasException(*JSGlobalObject) bool;
pub fn hasException(this: *JSGlobalObject) bool {
return JSGlobalObject__hasException(this);
}
pub fn vm(this: *JSGlobalObject) *VM {
return cppFn("vm", .{this});
}