Compare commits
No commits in common. "44c18c14236a56b7a073ef457046262bc1294fe0" and "bf7af082feb8adcaea32098e28bc5e510cbb44a7" have entirely different histories.
44c18c1423
...
bf7af082fe
16
README.md
16
README.md
|
@ -35,8 +35,6 @@ console.log(array);
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
#### Get an error
|
|
||||||
|
|
||||||
``` js
|
``` js
|
||||||
import { errors } from 'arsenal';
|
import { errors } from 'arsenal';
|
||||||
|
|
||||||
|
@ -48,17 +46,3 @@ console.log(errors.AccessDenied);
|
||||||
// AccessDenied: true }
|
// AccessDenied: true }
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Map an error
|
|
||||||
|
|
||||||
``` js
|
|
||||||
import { errors } from 'arsenal';
|
|
||||||
|
|
||||||
console.log(errors.DBNotFound.errorsMap());
|
|
||||||
|
|
||||||
// { [Error: NoSuchBucket]
|
|
||||||
// code: 404,
|
|
||||||
// description: 'The specified bucket does not exist.',
|
|
||||||
// NoSuchBucket: true }
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
3
index.js
3
index.js
|
@ -1,7 +1,6 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
db: require('./lib/db'),
|
db: require('./lib/db'),
|
||||||
errors: require('./lib/errors.js').errorsGen,
|
errors: require('./lib/errors.js'),
|
||||||
errorsClean: require('./lib/errors.js').errorsClean,
|
|
||||||
shuffle: require('./lib/shuffle'),
|
shuffle: require('./lib/shuffle'),
|
||||||
stringHash: require('./lib/stringHash'),
|
stringHash: require('./lib/stringHash'),
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
'use strict'; // eslint-disable-line strict
|
'use strict'; // eslint-disable-line strict
|
||||||
|
|
||||||
const errors = {};
|
|
||||||
|
|
||||||
class ArsenalError extends Error {
|
class ArsenalError extends Error {
|
||||||
constructor(type, code, desc) {
|
constructor(type, code, desc) {
|
||||||
super(type);
|
super(type);
|
||||||
|
@ -9,40 +7,6 @@ class ArsenalError extends Error {
|
||||||
this.description = desc;
|
this.description = desc;
|
||||||
this[type] = true;
|
this[type] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Map errors from MD to S3
|
|
||||||
* @returns {Object.<ArsenalError>} - the instance of the S3 corresponding
|
|
||||||
* error
|
|
||||||
*/
|
|
||||||
errorsMap() {
|
|
||||||
const map = {
|
|
||||||
NoSuchBucket: 'NoSuchBucket',
|
|
||||||
BucketAlreadyExists: 'BucketAlreadyExists',
|
|
||||||
NoSuchKey: 'NoSuchKey',
|
|
||||||
DBNotFound: 'NoSuchBucket',
|
|
||||||
DBAlreadyExists: 'BucketAlreadyExists',
|
|
||||||
ObjNotFound: 'NoSuchKey',
|
|
||||||
NotImplemented: 'NotImplemented',
|
|
||||||
};
|
|
||||||
return errors[map[this.message]] ? errors[map[this.message]] :
|
|
||||||
errors.InternalError;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Clean errors from vaultClient to S3
|
|
||||||
* @param {Object} obj - the vaultclient error
|
|
||||||
* @returns {Object.<ArsenalError>} - the instance of the S3 corresponding
|
|
||||||
* error
|
|
||||||
*/
|
|
||||||
function errorsClean(obj) {
|
|
||||||
let err;
|
|
||||||
Object.keys(obj.message).forEach(prop => {
|
|
||||||
if (obj.message[prop] === true)
|
|
||||||
err = errors[prop];
|
|
||||||
});
|
|
||||||
return (err);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -52,6 +16,7 @@ function errorsClean(obj) {
|
||||||
* instances
|
* instances
|
||||||
*/
|
*/
|
||||||
function errorsGen() {
|
function errorsGen() {
|
||||||
|
const errors = {};
|
||||||
const errorsObj = require('../errors/arsenalErrors.json');
|
const errorsObj = require('../errors/arsenalErrors.json');
|
||||||
|
|
||||||
Object.keys(errorsObj)
|
Object.keys(errorsObj)
|
||||||
|
@ -63,7 +28,4 @@ function errorsGen() {
|
||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = errorsGen();
|
||||||
errorsGen: errorsGen(),
|
|
||||||
errorsClean,
|
|
||||||
};
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git+https://github.com/scality/Arsenal.git"
|
"url": "git+https://github.com/scality/IronMan-Arsenal.git"
|
||||||
},
|
},
|
||||||
"contributors": [
|
"contributors": [
|
||||||
{ "name": "David Pineau", "email": "" },
|
{ "name": "David Pineau", "email": "" },
|
||||||
|
@ -14,15 +14,15 @@
|
||||||
],
|
],
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/scality/Arsenal/issues"
|
"url": "https://github.com/scality/IronMan-Arsenal/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/scality/Arsenal#readme",
|
"homepage": "https://github.com/scality/IronMan-Arsenal#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"eslint": "^2.4.0",
|
"eslint": "^2.4.0",
|
||||||
"eslint-config-airbnb": "^6.0.0",
|
"eslint-config-airbnb": "^6.0.0",
|
||||||
"eslint-config-ironman": "scality/Guidelines#rel/1.1",
|
"eslint-config-ironman": "scality/IronMan-Guidelines#rel/1.0",
|
||||||
"level": "^1.3.0",
|
"level": "^1.3.0",
|
||||||
"mocha": "^2.3.3",
|
"mocha": "^2.3.3",
|
||||||
"temp": "^0.8.3"
|
"temp": "^0.8.3"
|
||||||
|
|
|
@ -3,17 +3,6 @@ const assert = require('assert');
|
||||||
const errorsJSON = require('../../errors/arsenalErrors.json');
|
const errorsJSON = require('../../errors/arsenalErrors.json');
|
||||||
const errors = require('../../index').errors;
|
const errors = require('../../index').errors;
|
||||||
|
|
||||||
const map = {
|
|
||||||
NoSuchBucket: 'NoSuchBucket',
|
|
||||||
BucketAlreadyExists: 'BucketAlreadyExists',
|
|
||||||
NoSuchKey: 'NoSuchKey',
|
|
||||||
DBNotFound: 'NoSuchBucket',
|
|
||||||
DBAlreadyExists: 'BucketAlreadyExists',
|
|
||||||
ObjNotFound: 'NoSuchKey',
|
|
||||||
NotImplemented: 'NotImplemented',
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
describe('Runtime errors instance generation', () => {
|
describe('Runtime errors instance generation', () => {
|
||||||
Object.keys(errors).forEach(index => {
|
Object.keys(errors).forEach(index => {
|
||||||
it(`should return and instance of ${index} Error`, done => {
|
it(`should return and instance of ${index} Error`, done => {
|
||||||
|
@ -30,13 +19,3 @@ describe('Runtime errors instance generation', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Error map(wrapper) MD -> S3', () => {
|
|
||||||
Object.keys(map).forEach(index => {
|
|
||||||
it(`should return an instance of ${map[index]} Error`, done => {
|
|
||||||
assert.deepStrictEqual(errors[index].errorsMap(),
|
|
||||||
errors[map[index]]);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
Loading…
Reference in New Issue