UNPKG

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