1 | /**
|
2 | * Copyright (c) 2018, Kinvey, Inc. All rights reserved.
|
3 | *
|
4 | * This software is licensed to you under the Kinvey terms of service located at
|
5 | * http://www.kinvey.com/terms-of-use. By downloading, accessing and/or using this
|
6 | * software, you hereby accept such terms of service (and any agreement referenced
|
7 | * therein) and agree that you have read, understand and agree to be bound by such
|
8 | * terms of service and are of legal age to agree to such terms with Kinvey.
|
9 | *
|
10 | * This software contains valuable confidential and proprietary information of
|
11 | * KINVEY, INC and is subject to applicable licensing agreements.
|
12 | * Unauthorized reproduction, transmission or distribution of this file and its
|
13 | * contents is a violation of applicable laws.
|
14 | */
|
15 |
|
16 | /**
|
17 | * Creates a KinveyError.
|
18 | * @param {String|Object} nameOrObject The name of the error or an object containing name/NAME and message/MESSAGE.
|
19 | * @param {String} [message]
|
20 | * @constructor
|
21 | */
|
22 | function KinveyError(nameOrObject, message) {
|
23 | if (nameOrObject == null) {
|
24 | nameOrObject = 'GeneralError'; // eslint-disable-line no-param-reassign
|
25 | }
|
26 |
|
27 | let errorName;
|
28 |
|
29 | if (nameOrObject.NAME != null) {
|
30 | errorName = nameOrObject.NAME;
|
31 | } else if (nameOrObject.name != null) {
|
32 | errorName = nameOrObject.name;
|
33 | } else {
|
34 | errorName = nameOrObject;
|
35 | }
|
36 |
|
37 | this.name = errorName;
|
38 | this.message = message || (nameOrObject.message || nameOrObject.MESSAGE) || '';
|
39 | this.stack = (new Error()).stack;
|
40 | }
|
41 |
|
42 | KinveyError.prototype = Object.create(Error.prototype);
|
43 | KinveyError.prototype.constructor = KinveyError;
|
44 |
|
45 | module.exports = KinveyError;
|