UNPKG

3.37 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
5Object.defineProperty(exports, "__esModule", {
6 value: true
7});
8exports.newError = newError;
9exports.PROTOCOL_ERROR = exports.SESSION_EXPIRED = exports.SERVICE_UNAVAILABLE = exports.Neo4jError = void 0;
10
11var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
12
13var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
14
15var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
16
17var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
18
19var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapNativeSuper"));
20
21/**
22 * Copyright (c) 2002-2019 "Neo4j,"
23 * Neo4j Sweden AB [http://neo4j.com]
24 *
25 * This file is part of Neo4j.
26 *
27 * Licensed under the Apache License, Version 2.0 (the "License");
28 * you may not use this file except in compliance with the License.
29 * You may obtain a copy of the License at
30 *
31 * http://www.apache.org/licenses/LICENSE-2.0
32 *
33 * Unless required by applicable law or agreed to in writing, software
34 * distributed under the License is distributed on an "AS IS" BASIS,
35 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
36 * See the License for the specific language governing permissions and
37 * limitations under the License.
38 */
39// A common place for constructing error objects, to keep them
40// uniform across the driver surface.
41
42/**
43 * Error code representing complete loss of service. Used by {@link Neo4jError#code}.
44 * @type {string}
45 */
46var SERVICE_UNAVAILABLE = 'ServiceUnavailable';
47/**
48 * Error code representing transient loss of service. Used by {@link Neo4jError#code}.
49 * @type {string}
50 */
51
52exports.SERVICE_UNAVAILABLE = SERVICE_UNAVAILABLE;
53var SESSION_EXPIRED = 'SessionExpired';
54/**
55 * Error code representing serialization/deserialization issue in the Bolt protocol. Used by {@link Neo4jError#code}.
56 * @type {string}
57 */
58
59exports.SESSION_EXPIRED = SESSION_EXPIRED;
60var PROTOCOL_ERROR = 'ProtocolError';
61exports.PROTOCOL_ERROR = PROTOCOL_ERROR;
62
63function newError(message) {
64 var code = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'N/A';
65 // TODO: Idea is that we can check the code here and throw sub-classes
66 // of Neo4jError as appropriate
67 return new Neo4jError(message, code);
68}
69/**
70 * Class for all errors thrown/returned by the driver.
71 */
72
73
74var Neo4jError =
75/*#__PURE__*/
76function (_Error) {
77 (0, _inherits2["default"])(Neo4jError, _Error);
78
79 /**
80 * @constructor
81 * @param {string} message - The error message.
82 * @param {string} code - Optional error code. Will be populated when error originates in the database.
83 */
84 function Neo4jError(message) {
85 var _this;
86
87 var code = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'N/A';
88 (0, _classCallCheck2["default"])(this, Neo4jError);
89 _this = (0, _possibleConstructorReturn2["default"])(this, (0, _getPrototypeOf2["default"])(Neo4jError).call(this, message));
90 _this.message = message;
91 _this.code = code;
92 _this.name = 'Neo4jError';
93 return _this;
94 }
95
96 return Neo4jError;
97}((0, _wrapNativeSuper2["default"])(Error));
98
99exports.Neo4jError = Neo4jError;
\No newline at end of file