| 
									
										
										
										
											2022-10-12 11:14:59 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2022, Florent Castelli <florent.castelli@gmail.com> | 
					
						
							|  |  |  |  * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  | #include <AK/DeprecatedString.h>
 | 
					
						
							| 
									
										
										
										
											2022-11-02 21:56:33 +00:00
										 |  |  | #include <AK/JsonValue.h>
 | 
					
						
							| 
									
										
										
										
											2022-10-12 11:14:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-08 10:10:27 -05:00
										 |  |  | namespace Web::WebDriver { | 
					
						
							| 
									
										
										
										
											2022-10-12 11:14:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-21 12:51:41 +01:00
										 |  |  | // https://w3c.github.io/webdriver/#dfn-error-code
 | 
					
						
							|  |  |  | enum class ErrorCode { | 
					
						
							|  |  |  |     ElementClickIntercepted, | 
					
						
							|  |  |  |     ElementNotInteractable, | 
					
						
							|  |  |  |     InsecureCertificate, | 
					
						
							|  |  |  |     InvalidArgument, | 
					
						
							|  |  |  |     InvalidCookieDomain, | 
					
						
							|  |  |  |     InvalidElementState, | 
					
						
							|  |  |  |     InvalidSelector, | 
					
						
							|  |  |  |     InvalidSessionId, | 
					
						
							|  |  |  |     JavascriptError, | 
					
						
							|  |  |  |     MoveTargetOutOfBounds, | 
					
						
							|  |  |  |     NoSuchAlert, | 
					
						
							|  |  |  |     NoSuchCookie, | 
					
						
							|  |  |  |     NoSuchElement, | 
					
						
							|  |  |  |     NoSuchFrame, | 
					
						
							|  |  |  |     NoSuchWindow, | 
					
						
							|  |  |  |     NoSuchShadowRoot, | 
					
						
							|  |  |  |     ScriptTimeoutError, | 
					
						
							|  |  |  |     SessionNotCreated, | 
					
						
							|  |  |  |     StaleElementReference, | 
					
						
							|  |  |  |     DetachedShadowRoot, | 
					
						
							|  |  |  |     Timeout, | 
					
						
							|  |  |  |     UnableToSetCookie, | 
					
						
							|  |  |  |     UnableToCaptureScreen, | 
					
						
							|  |  |  |     UnexpectedAlertOpen, | 
					
						
							|  |  |  |     UnknownCommand, | 
					
						
							|  |  |  |     UnknownError, | 
					
						
							|  |  |  |     UnknownMethod, | 
					
						
							|  |  |  |     UnsupportedOperation, | 
					
						
							| 
									
										
										
										
											2023-03-05 15:26:51 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // Non-standard error codes:
 | 
					
						
							|  |  |  |     OutOfMemory, | 
					
						
							| 
									
										
										
										
											2022-10-21 12:51:41 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // https://w3c.github.io/webdriver/#errors
 | 
					
						
							| 
									
										
										
										
											2022-11-08 10:10:27 -05:00
										 |  |  | struct Error { | 
					
						
							| 
									
										
										
										
											2022-10-12 11:14:59 +01:00
										 |  |  |     unsigned http_status; | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |     DeprecatedString error; | 
					
						
							|  |  |  |     DeprecatedString message; | 
					
						
							| 
									
										
										
										
											2022-11-02 21:56:33 +00:00
										 |  |  |     Optional<JsonValue> data; | 
					
						
							| 
									
										
										
										
											2022-10-21 12:51:41 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |     static Error from_code(ErrorCode, DeprecatedString message, Optional<JsonValue> data = {}); | 
					
						
							| 
									
										
										
										
											2023-03-05 15:26:51 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     Error(unsigned http_status, DeprecatedString error, DeprecatedString message, Optional<JsonValue> data); | 
					
						
							|  |  |  |     Error(AK::Error const&); | 
					
						
							| 
									
										
										
										
											2022-10-12 11:14:59 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | template<> | 
					
						
							| 
									
										
										
										
											2022-11-08 10:10:27 -05:00
										 |  |  | struct AK::Formatter<Web::WebDriver::Error> : Formatter<StringView> { | 
					
						
							|  |  |  |     ErrorOr<void> format(FormatBuilder& builder, Web::WebDriver::Error const& error) | 
					
						
							| 
									
										
										
										
											2022-10-12 11:14:59 +01:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2022-12-04 18:02:33 +00:00
										 |  |  |         return Formatter<StringView>::format(builder, DeprecatedString::formatted("Error {}, {}: {}", error.http_status, error.error, error.message)); | 
					
						
							| 
									
										
										
										
											2022-10-12 11:14:59 +01:00
										 |  |  |     } | 
					
						
							|  |  |  | }; |