mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-28 22:53:28 +00:00
cdp: add send error options with session id by default
This commit is contained in:
@@ -151,18 +151,18 @@ pub fn CDPT(comptime TypeProvider: type) type {
|
||||
if (std.mem.eql(u8, input_session_id, "STARTUP")) {
|
||||
is_startup = true;
|
||||
} else if (self.isValidSessionId(input_session_id) == false) {
|
||||
return command.sendError(-32001, "Unknown sessionId");
|
||||
return command.sendError(-32001, "Unknown sessionId", .{});
|
||||
}
|
||||
}
|
||||
|
||||
if (is_startup) {
|
||||
dispatchStartupCommand(&command) catch |err| {
|
||||
command.sendError(-31999, @errorName(err)) catch {};
|
||||
command.sendError(-31999, @errorName(err), .{}) catch {};
|
||||
return err;
|
||||
};
|
||||
} else {
|
||||
dispatchCommand(&command, input.method) catch |err| {
|
||||
command.sendError(-31998, @errorName(err)) catch {};
|
||||
command.sendError(-31998, @errorName(err), .{}) catch {};
|
||||
return err;
|
||||
};
|
||||
}
|
||||
@@ -757,10 +757,14 @@ pub fn Command(comptime CDP_T: type, comptime Sender: type) type {
|
||||
return self.cdp.sendEvent(method, p, opts);
|
||||
}
|
||||
|
||||
pub fn sendError(self: *Self, code: i32, message: []const u8) !void {
|
||||
const SendErrorOpts = struct {
|
||||
include_session_id: bool = true,
|
||||
};
|
||||
pub fn sendError(self: *Self, code: i32, message: []const u8, opts: SendErrorOpts) !void {
|
||||
return self.sender.sendJSON(.{
|
||||
.id = self.input.id,
|
||||
.@"error" = .{ .code = code, .message = message },
|
||||
.sessionId = if (opts.include_session_id) self.input.session_id else null,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -471,7 +471,7 @@ fn getFrameOwner(cmd: anytype) !void {
|
||||
const bc = cmd.browser_context orelse return error.BrowserContextNotLoaded;
|
||||
const target_id = bc.target_id orelse return error.TargetNotLoaded;
|
||||
if (std.mem.eql(u8, target_id, params.frameId) == false) {
|
||||
return cmd.sendError(-32000, "Frame with the given id does not belong to the target.");
|
||||
return cmd.sendError(-32000, "Frame with the given id does not belong to the target.", .{});
|
||||
}
|
||||
|
||||
const page = bc.session.currentPage() orelse return error.PageNotLoaded;
|
||||
|
||||
@@ -79,7 +79,7 @@ fn createBrowserContext(cmd: anytype) !void {
|
||||
}
|
||||
|
||||
const bc = cmd.createBrowserContext() catch |err| switch (err) {
|
||||
error.AlreadyExists => return cmd.sendError(-32000, "Cannot have more than one browser context at a time"),
|
||||
error.AlreadyExists => return cmd.sendError(-32000, "Cannot have more than one browser context at a time", .{}),
|
||||
else => return err,
|
||||
};
|
||||
|
||||
@@ -102,7 +102,7 @@ fn disposeBrowserContext(cmd: anytype) !void {
|
||||
})) orelse return error.InvalidParams;
|
||||
|
||||
if (cmd.cdp.disposeBrowserContext(params.browserContextId) == false) {
|
||||
return cmd.sendError(-32602, "No browser context with the given id found");
|
||||
return cmd.sendError(-32602, "No browser context with the given id found", .{});
|
||||
}
|
||||
try cmd.sendResult(null, .{});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user