MCPcopy Create free account
hub / github.com/SeleniumHQ/selenium / FromErrorJson

Method FromErrorJson

dotnet/src/webdriver/Response.cs:137–166  ·  view source on GitHub ↗

Returns a new from a JSON-encoded string. The JSON string to deserialize into a . A object described by the JSON string. If is . If <

(string value)

Source from the content-addressed store, hash-verified

135 /// <exception cref="JsonException">If <paramref name="value"/> is not a valid JSON object.</exception>
136 /// <exception cref="WebDriverException">If the JSON dictionary is not in the expected state, per spec.</exception>
137 public static Response FromErrorJson(string value)
138 {
139 JsonObject responseObject = JsonNode.Parse(value) as JsonObject
140 ?? throw new WebDriverException($"JSON error response did not return an object{Environment.NewLine}{value}");
141
142 if (!responseObject.TryGetPropertyValue("value", out JsonNode? valueNode))
143 {
144 throw new WebDriverException($"The 'value' property was not found in the response{Environment.NewLine}{value}");
145 }
146
147 if (valueNode is not JsonObject valueObject)
148 {
149 throw new WebDriverException($"The 'value' property is not a dictionary{Environment.NewLine}{value}");
150 }
151
152 if (!valueObject.TryGetPropertyValue("error", out JsonNode? errorObject))
153 {
154 throw new WebDriverException($"The 'value > error' property was not found in the response{Environment.NewLine}{value}");
155 }
156
157 if (errorObject is not JsonValue errorValue || !errorValue.TryGetValue(out string? errorString))
158 {
159 throw new WebDriverException($"The 'value > error' property is not a string{Environment.NewLine}{value}");
160 }
161
162 var valueDictionary = JsonSerializer.Deserialize(valueObject, ResponseJsonSerializerContext.Default.Object);
163 WebDriverResult status = WebDriverError.ResultFromError(errorString);
164
165 return new Response(sessionId: null, valueDictionary, status);
166 }
167
168 /// <summary>
169 /// Returns this object as a JSON-encoded string.

Callers 1

CreateResponseMethod · 0.80

Calls 3

ResultFromErrorMethod · 0.80
TryGetValueMethod · 0.45
DeserializeMethod · 0.45

Tested by

no test coverage detected