aboutsummaryrefslogtreecommitdiff
path: root/node_modules/algoliasearch/src/errors.js
diff options
context:
space:
mode:
authorruki <waruqi@gmail.com>2018-11-08 00:38:48 +0800
committerruki <waruqi@gmail.com>2018-11-07 21:53:09 +0800
commit26105034da4fcce7ac883c899d781f016559310d (patch)
treec459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/algoliasearch/src/errors.js
parent2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff)
downloadxmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz
xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip
switch to vuepress
Diffstat (limited to 'node_modules/algoliasearch/src/errors.js')
-rw-r--r--node_modules/algoliasearch/src/errors.js78
1 files changed, 78 insertions, 0 deletions
diff --git a/node_modules/algoliasearch/src/errors.js b/node_modules/algoliasearch/src/errors.js
new file mode 100644
index 00000000..31154503
--- /dev/null
+++ b/node_modules/algoliasearch/src/errors.js
@@ -0,0 +1,78 @@
+'use strict';
+
+// This file hosts our error definitions
+// We use custom error "types" so that we can act on them when we need it
+// e.g.: if error instanceof errors.UnparsableJSON then..
+
+var inherits = require('inherits');
+
+function AlgoliaSearchError(message, extraProperties) {
+ var forEach = require('foreach');
+
+ var error = this;
+
+ // try to get a stacktrace
+ if (typeof Error.captureStackTrace === 'function') {
+ Error.captureStackTrace(this, this.constructor);
+ } else {
+ error.stack = (new Error()).stack || 'Cannot get a stacktrace, browser is too old';
+ }
+
+ this.name = 'AlgoliaSearchError';
+ this.message = message || 'Unknown error';
+
+ if (extraProperties) {
+ forEach(extraProperties, function addToErrorObject(value, key) {
+ error[key] = value;
+ });
+ }
+}
+
+inherits(AlgoliaSearchError, Error);
+
+function createCustomError(name, message) {
+ function AlgoliaSearchCustomError() {
+ var args = Array.prototype.slice.call(arguments, 0);
+
+ // custom message not set, use default
+ if (typeof args[0] !== 'string') {
+ args.unshift(message);
+ }
+
+ AlgoliaSearchError.apply(this, args);
+ this.name = 'AlgoliaSearch' + name + 'Error';
+ }
+
+ inherits(AlgoliaSearchCustomError, AlgoliaSearchError);
+
+ return AlgoliaSearchCustomError;
+}
+
+// late exports to let various fn defs and inherits take place
+module.exports = {
+ AlgoliaSearchError: AlgoliaSearchError,
+ UnparsableJSON: createCustomError(
+ 'UnparsableJSON',
+ 'Could not parse the incoming response as JSON, see err.more for details'
+ ),
+ RequestTimeout: createCustomError(
+ 'RequestTimeout',
+ 'Request timedout before getting a response'
+ ),
+ Network: createCustomError(
+ 'Network',
+ 'Network issue, see err.more for details'
+ ),
+ JSONPScriptFail: createCustomError(
+ 'JSONPScriptFail',
+ '<script> was loaded but did not call our provided callback'
+ ),
+ JSONPScriptError: createCustomError(
+ 'JSONPScriptError',
+ '<script> unable to load due to an `error` event on it'
+ ),
+ Unknown: createCustomError(
+ 'Unknown',
+ 'Unknown error occured'
+ )
+};