protocolError.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.ProtocolError = void 0;
  6. exports.isProtocolError = isProtocolError;
  7. exports.isSessionClosedError = isSessionClosedError;
  8. var _stackTrace = require("../utils/stackTrace");
  9. /**
  10. * Copyright (c) Microsoft Corporation.
  11. *
  12. * Licensed under the Apache License, Version 2.0 (the "License");
  13. * you may not use this file except in compliance with the License.
  14. * You may obtain a copy of the License at
  15. *
  16. * http://www.apache.org/licenses/LICENSE-2.0
  17. *
  18. * Unless required by applicable law or agreed to in writing, software
  19. * distributed under the License is distributed on an "AS IS" BASIS,
  20. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  21. * See the License for the specific language governing permissions and
  22. * limitations under the License.
  23. */
  24. class ProtocolError extends Error {
  25. constructor(type, method, logs) {
  26. super();
  27. this.type = void 0;
  28. this.method = void 0;
  29. this.logs = void 0;
  30. this.type = type;
  31. this.method = method;
  32. this.logs = logs;
  33. }
  34. setMessage(message) {
  35. (0, _stackTrace.rewriteErrorMessage)(this, `Protocol error (${this.method}): ${message}`);
  36. }
  37. browserLogMessage() {
  38. return this.logs ? '\nBrowser logs:\n' + this.logs : '';
  39. }
  40. }
  41. exports.ProtocolError = ProtocolError;
  42. function isProtocolError(e) {
  43. return e instanceof ProtocolError;
  44. }
  45. function isSessionClosedError(e) {
  46. return e instanceof ProtocolError && (e.type === 'closed' || e.type === 'crashed');
  47. }