Error.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright (c) 2022, Florent Castelli <florent.castelli@gmail.com>
  3. * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/DeprecatedString.h>
  9. #include <AK/JsonValue.h>
  10. namespace Web::WebDriver {
  11. // https://w3c.github.io/webdriver/#dfn-error-code
  12. enum class ErrorCode {
  13. ElementClickIntercepted,
  14. ElementNotInteractable,
  15. InsecureCertificate,
  16. InvalidArgument,
  17. InvalidCookieDomain,
  18. InvalidElementState,
  19. InvalidSelector,
  20. InvalidSessionId,
  21. JavascriptError,
  22. MoveTargetOutOfBounds,
  23. NoSuchAlert,
  24. NoSuchCookie,
  25. NoSuchElement,
  26. NoSuchFrame,
  27. NoSuchWindow,
  28. NoSuchShadowRoot,
  29. ScriptTimeoutError,
  30. SessionNotCreated,
  31. StaleElementReference,
  32. DetachedShadowRoot,
  33. Timeout,
  34. UnableToSetCookie,
  35. UnableToCaptureScreen,
  36. UnexpectedAlertOpen,
  37. UnknownCommand,
  38. UnknownError,
  39. UnknownMethod,
  40. UnsupportedOperation,
  41. };
  42. // https://w3c.github.io/webdriver/#errors
  43. struct Error {
  44. unsigned http_status;
  45. DeprecatedString error;
  46. DeprecatedString message;
  47. Optional<JsonValue> data;
  48. static Error from_code(ErrorCode, DeprecatedString message, Optional<JsonValue> data = {});
  49. };
  50. }
  51. template<>
  52. struct AK::Formatter<Web::WebDriver::Error> : Formatter<StringView> {
  53. ErrorOr<void> format(FormatBuilder& builder, Web::WebDriver::Error const& error)
  54. {
  55. return Formatter<StringView>::format(builder, DeprecatedString::formatted("Error {}, {}: {}", error.http_status, error.error, error.message));
  56. }
  57. };