elasticsearch-exceptions
Advanced tools
Comparing version 0.0.2 to 0.0.4
@@ -6,19 +6,15 @@ 'use strict'; | ||
var exceptions = require('./exceptions'); | ||
// create factory helper | ||
module.exports = function createExceptionfromError(err) { | ||
// @todo | ||
}; | ||
['AliasMissing', 'IndexMissing'].forEach(function (moduleName) { | ||
// append | ||
var exception = require(getModuleFile(moduleName)); | ||
module.exports[moduleName] = exception; | ||
exceptions.SUPPORTED.forEach(function (exception_name) { | ||
module.exports[exception_name] = exceptions[exception_name]; | ||
// create "is{ExceptionName}" helper | ||
module.exports['is' + moduleName] = createIsGetter(exception, moduleName); | ||
module.exports['is' + exception_name] = createIsGetter(exceptions[exception_name]); | ||
}); | ||
function getModuleFile(moduleName) { | ||
return p.resolve(__dirname, './exceptions', moduleName + '.exception'); | ||
} | ||
function createIsGetter(module) { | ||
@@ -25,0 +21,0 @@ assert(_.isFunction(module.is)); // module should implement is(err) -> boolean |
'use strict'; | ||
var assert = require('better-assert'); | ||
var ElasticSearchExceptions = require('./'); | ||
var Exceptions = require('./'); | ||
describe('ElasticSearchExceptions', function () { | ||
describe('ElasticSearchExceptions.isIndexMissing(err)', function () { | ||
var INDEX_MISSING_ESERR = new ElasticSearchExceptions.IndexMissing("IndexMissingException[[aliasbringr-20141211-20141212] missing"); | ||
var INDEX_MISSING_ERR = new Error('IndexMissingException[[aliasbringr-20141211-20141212] missing]]'); | ||
describe('Exceptions', function () { | ||
describe('Exceptions.isAggregationExecutionException(err)', function () { | ||
var INDEX_MISSING_ESERR = new Exceptions.AggregationExecutionException("AggregationExecutionException[[qsdoijqspodij-20141211-20141212] missing"); | ||
var INDEX_MISSING_ERR = new Error('AggregationExecutionException[[qsdoijqspodij-20141211-20141212] missing]]'); | ||
it('should return false if this is not an alias missing error', function () { | ||
assert(ElasticSearchExceptions.isIndexMissing() === false); | ||
assert(ElasticSearchExceptions.isIndexMissing({}) === false); | ||
assert(ElasticSearchExceptions.isIndexMissing(new Error('plop')) === false); | ||
assert(Exceptions.isAggregationExecutionException() === false); | ||
assert(Exceptions.isAggregationExecutionException({}) === false); | ||
assert(Exceptions.isAggregationExecutionException(new Error('plop')) === false); | ||
}); | ||
it('should return true if this is an alias missing error', function () { | ||
assert(ElasticSearchExceptions.isIndexMissing(INDEX_MISSING_ERR) === true); | ||
assert(ElasticSearchExceptions.isIndexMissing(INDEX_MISSING_ESERR) === true); | ||
assert(Exceptions.isAggregationExecutionException(INDEX_MISSING_ERR) === true); | ||
assert(Exceptions.isAggregationExecutionException(INDEX_MISSING_ESERR) === true); | ||
}); | ||
}); | ||
describe('ElasticSearchExceptions.isAliasMissing(err)', function () { | ||
var ALIAS_MISSING_ERR = new Error('AliasMissingException[[aliasbringr-20141211-20141212] missing]]'); | ||
var ALIAS_MISSING_ESERR = new ElasticSearchExceptions.AliasMissing("AliasMissingException[[aliasbringr-20141211-20141212] missing]]"); | ||
describe('Exceptions.isAliasesMissingException(err)', function () { | ||
var ALIAS_MISSING_ERR = new Error('AliasesMissingException[[qsdoijqspodij-20141211-20141212] missing]]'); | ||
var ALIAS_MISSING_ESERR = new Exceptions.AliasesMissingException("AliasesMissingException[[qsdoijqspodij-20141211-20141212] missing]]"); | ||
it('should return false if this is not an alias missing error', function () { | ||
assert(ElasticSearchExceptions.isAliasMissing() === false); | ||
assert(ElasticSearchExceptions.isAliasMissing({}) === false); | ||
assert(ElasticSearchExceptions.isAliasMissing(new Error('plop')) === false); | ||
assert(Exceptions.isAliasesMissingException() === false); | ||
assert(Exceptions.isAliasesMissingException({}) === false); | ||
assert(Exceptions.isAliasesMissingException(new Error('plop')) === false); | ||
}); | ||
it('should return true if this is an alias missing error', function () { | ||
assert(ElasticSearchExceptions.isAliasMissing(ALIAS_MISSING_ERR) === true); | ||
assert(ElasticSearchExceptions.isAliasMissing(ALIAS_MISSING_ESERR) === true); | ||
assert(Exceptions.isAliasesMissingException(ALIAS_MISSING_ERR) === true); | ||
assert(Exceptions.isAliasesMissingException(ALIAS_MISSING_ESERR) === true); | ||
}); | ||
}); | ||
}); |
{ | ||
"name": "elasticsearch-exceptions", | ||
"version": "0.0.2", | ||
"version": "0.0.4", | ||
"description": "Parse Elasticsearch exception responses and transform them into JavaScript Errors", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -12,10 +12,6 @@ Elasticsearch-exceptions | ||
``` | ||
var ElasticsearchExceptions = require('elasticsearch-exceptions'); | ||
var EsEx = require('elasticsearch-exceptions'); | ||
someRequestToElasticSearchOrUsingANodeJSClient(function(err, ok){ | ||
if(ElasticsearchExceptions.isIndexMissing(err)){ | ||
// do something | ||
} | ||
if(ElasticsearchExceptions.isAliasMissing(err)){ | ||
if(EsEx.isAliasesMissingException(err)){ | ||
// do something else | ||
@@ -30,1 +26,74 @@ } | ||
}); | ||
``` | ||
# Supported exceptions (Elasticsearch v1.4.0) | ||
```javascript | ||
[ | ||
'AggregationExecutionException', | ||
'AggregationInitializationException', | ||
'AliasesMissingException', | ||
'AlreadyExpiredException', | ||
'BlobStoreException', | ||
'CircuitBreakingException', | ||
'ClusterBlockException', | ||
'DelayRecoveryException', | ||
'DiscoveryException', | ||
'ElasticsearchException.WithRestHeaders', | ||
'ElasticsearchGenerationException', | ||
'ElasticsearchIllegalArgumentException', | ||
'ElasticsearchIllegalStateException', | ||
'ElasticsearchNullPointerException', | ||
'ElasticsearchParseException', | ||
'ElasticsearchTimeoutException', | ||
'EsRejectedExecutionException', | ||
'ExpressionScriptCompilationException', | ||
'ExpressionScriptExecutionException', | ||
'FacetPhaseExecutionException', | ||
'FailedNodeException', | ||
'FailedToResolveConfigException', | ||
'GatewayException', | ||
'GroovyScriptCompilationException', | ||
'GroovyScriptExecutionException', | ||
'HttpException', | ||
'IgnoreRecoveryException', | ||
'IndexException', | ||
'IndexShardAlreadyExistsException', | ||
'IndexTemplateAlreadyExistsException', | ||
'IndexTemplateMissingException', | ||
'IndexMissingException', | ||
'IndexWarmerMissingException', | ||
'InvalidIndexTemplateException', | ||
'Lucene.EarlyTerminationException', | ||
'MapperException', | ||
'MasterNotDiscoveredException', | ||
'NodeClosedException', | ||
'NoNodeAvailableException', | ||
'PercolateException', | ||
'PrimaryMissingActionException', | ||
'ProcessClusterEventTimeoutException', | ||
'RecoveryFailedException', | ||
'RepositoryException', | ||
'RiverException', | ||
'RoutingException', | ||
'RoutingMissingException', | ||
'ScriptException', | ||
'SearchContextMissingException', | ||
'SearchException', | ||
'SearchPhaseExecutionException', | ||
'SearchSourceBuilderException', | ||
'SettingsException', | ||
'SnapshotException', | ||
'SuggestBuilderException', | ||
'TimestampParsingException', | ||
'TranslogCorruptedException', | ||
'TransportException', | ||
'UnavailableShardsException', | ||
'UncategorizedExecutionException' | ||
] | ||
``` | ||
# Todo | ||
- transform elasticsearch client errors to elasticsearch-exceptions | ||
- parse exception body |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
19212
140
98
0
1