AMBARI-14647 Add base error types. (ababiichuk)

Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/e080e678
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/e080e678
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/e080e678

Branch: refs/heads/branch-dev-patch-upgrade
Commit: e080e678ac766f407065cdc2c670c9ccdbe5d23e
Parents: ce192a4
Author: ababiichuk <ababiic...@hortonworks.com>
Authored: Wed Jan 13 12:36:35 2016 +0200
Committer: ababiichuk <ababiic...@hortonworks.com>
Committed: Wed Jan 13 14:38:49 2016 +0200

----------------------------------------------------------------------
 ambari-web/app/utils.js                    |  1 +
 ambari-web/app/utils/errors/assertions.js  | 86 ++++++++++++++++++++++++
 ambari-web/app/utils/errors/definitions.js | 87 +++++++++++++++++++++++++
 3 files changed, 174 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/e080e678/ambari-web/app/utils.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils.js b/ambari-web/app/utils.js
index dccbe5a..920aa55 100644
--- a/ambari-web/app/utils.js
+++ b/ambari-web/app/utils.js
@@ -19,6 +19,7 @@
 
 // load needed utils here
 
+require('utils/errors/assertions');
 require('utils/base64');
 require('utils/db');
 require('utils/helper');

http://git-wip-us.apache.org/repos/asf/ambari/blob/e080e678/ambari-web/app/utils/errors/assertions.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/errors/assertions.js 
b/ambari-web/app/utils/errors/assertions.js
new file mode 100644
index 0000000..ef7485e
--- /dev/null
+++ b/ambari-web/app/utils/errors/assertions.js
@@ -0,0 +1,86 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var App = require('app');
+require('utils/errors/definitions');
+
+/**
+ * Method to check custom statement and
+ * throws custom error if statement is false
+ *
+ * @param desc
+ * @param test
+ * @param ErrorObject
+ */
+App.assert = function(desc, test, ErrorObject) {
+  if (!test) {
+    ErrorObject = ErrorObject || Error;
+    throw new ErrorObject(desc ? ' Info:  ' + desc : '');
+  }
+};
+
+/**
+ * Check if passed variable should be not null
+ *
+ * @param object
+ * @param desc
+ */
+App.assertExists = function(object, desc) {
+  App.assert(desc, !Em.isNone(object), App.NotNullTypeError);
+};
+
+/**
+ * Check if passed variable is object
+ *
+ * @param object
+ * @param desc
+ */
+App.assertObject = function(object, desc) {
+  App.assert(desc, (typeof object === 'object') && object, 
App.ObjectTypeError);
+};
+
+/**
+ * Check if variable is instance of ember object
+ *
+ * @param object
+ * @param desc
+ */
+App.assertEmberObject = function(object, desc) {
+  App.assert(desc, Em.typeOf(object) === 'instance', App.EmberObjectTypeError);
+};
+
+/**
+ * Check if variable is array
+ *
+ * @param object
+ * @param desc
+ */
+App.assertArray = function(object, desc) {
+  App.assert(desc, Em.isArray(object), App.ArrayTypeError);
+};
+
+/**
+ * Check if variable is function
+ *
+ * @param object
+ * @param desc
+ */
+App.assertFunction = function(object, desc) {
+  App.assert(desc, Em.typeOf(object) === 'function', App.FunctionTypeError);
+};
+

http://git-wip-us.apache.org/repos/asf/ambari/blob/e080e678/ambari-web/app/utils/errors/definitions.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/errors/definitions.js 
b/ambari-web/app/utils/errors/definitions.js
new file mode 100644
index 0000000..973bb4a
--- /dev/null
+++ b/ambari-web/app/utils/errors/definitions.js
@@ -0,0 +1,87 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+var App = require('app');
+
+/**
+ * Error that should be used when
+ * not null type required
+ *
+ * @param message
+ * @constructor
+ */
+App.NotNullTypeError = function(message) {
+  this.name = "NotNullTypeError";
+  this.message = "Not null expected. " + (message || "");
+};
+
+App.NotNullTypeError.prototype = new TypeError();
+
+/**
+ * Error that should be used when
+ * object required
+ *
+ * @param message
+ * @constructor
+ */
+App.ObjectTypeError = function(message) {
+  this.name = "ObjectTypeError";
+  this.message = "Object expected. " + (message || "");
+};
+
+App.ObjectTypeError.prototype = new App.NotNullTypeError();
+
+/**
+ * Error that should be used when
+ * array required
+ *
+ * @param message
+ * @constructor
+ */
+App.ArrayTypeError = function(message) {
+  this.name = "ArrayTypeError";
+  this.message = "Array expected. " + (message || "");
+};
+
+App.ArrayTypeError.prototype = new App.NotNullTypeError();
+/**
+ * Error that should be used when
+ * function required
+ *
+ * @param message
+ * @constructor
+ */
+App.FunctionTypeError = function(message) {
+  this.name = "FunctionTypeError";
+  this.message = "Function expected. " + (message || "");
+};
+
+App.FunctionTypeError.prototype = new App.NotNullTypeError();
+/**
+ * Error that should be used when
+ * ember object required
+ *
+ * @param message
+ * @constructor
+ */
+App.EmberObjectTypeError = function(message) {
+  this.name = "EmberObjectTypeError";
+  this.message = "Ember object expected. " + (message || "");
+};
+
+App.EmberObjectTypeError.prototype = new App.ObjectTypeError();
\ No newline at end of file

Reply via email to