1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:57:35 +00:00

WebDriver: Support "data" field in error responses

This commit is contained in:
Linus Groh 2022-11-02 21:56:33 +00:00
parent 747ba2a88f
commit 6e1131e6de
3 changed files with 11 additions and 6 deletions

View file

@ -229,6 +229,8 @@ ErrorOr<void> Client::send_error_response(WebDriverError const& error, HTTP::Htt
result.set("error", error.error); result.set("error", error.error);
result.set("message", error.message); result.set("message", error.message);
result.set("stacktrace", ""); result.set("stacktrace", "");
if (error.data.has_value())
result.set("data", *error.data);
StringBuilder content_builder; StringBuilder content_builder;
result.serialize(content_builder); result.serialize(content_builder);

View file

@ -47,13 +47,14 @@ static Vector<ErrorCodeData> const s_error_code_data = {
{ ErrorCode::UnsupportedOperation, 500, "unsupported operation" }, { ErrorCode::UnsupportedOperation, 500, "unsupported operation" },
}; };
WebDriverError WebDriverError::from_code(ErrorCode code, String message) WebDriverError WebDriverError::from_code(ErrorCode code, String message, Optional<JsonValue> data)
{ {
auto& data = s_error_code_data[to_underlying(code)]; auto const& error_code_data = s_error_code_data[to_underlying(code)];
return { return {
.http_status = data.http_status, .http_status = error_code_data.http_status,
.error = data.json_error_code, .error = error_code_data.json_error_code,
.message = move(message) .message = move(message),
.data = move(data)
}; };
} }

View file

@ -7,6 +7,7 @@
#pragma once #pragma once
#include <AK/JsonValue.h>
#include <AK/String.h> #include <AK/String.h>
namespace WebDriver { namespace WebDriver {
@ -48,8 +49,9 @@ struct WebDriverError {
unsigned http_status; unsigned http_status;
String error; String error;
String message; String message;
Optional<JsonValue> data;
static WebDriverError from_code(ErrorCode, String message); static WebDriverError from_code(ErrorCode, String message, Optional<JsonValue> data = {});
}; };
} }