Compare commits
2 Commits
developmen
...
dev/FT/map
Author | SHA1 | Date |
---|---|---|
David Pineau | 37efe0c617 | |
Antonin Coulibaly | fc61e60bd5 |
14
README.md
14
README.md
|
@ -46,3 +46,17 @@ console.log(errors.AccessDenied);
|
|||
// AccessDenied: true }
|
||||
|
||||
```
|
||||
|
||||
#### Map an error
|
||||
|
||||
``` js
|
||||
import { errors } from 'arsenal';
|
||||
|
||||
console.log(errors.DBNotFound.toS3());
|
||||
|
||||
// { [Error: NoSuchBucket]
|
||||
// code: 404,
|
||||
// description: 'The specified bucket does not exist.',
|
||||
// NoSuchBucket: true }
|
||||
|
||||
```
|
||||
|
|
|
@ -618,50 +618,86 @@
|
|||
"_comment": "#### formatErrors ####",
|
||||
"DBNotFound": {
|
||||
"description": "This DB does not exist",
|
||||
"code": 404
|
||||
"code": 404,
|
||||
"translation": {
|
||||
"S3": "NoSuchBucket"
|
||||
}
|
||||
},
|
||||
"DBAlreadyExists": {
|
||||
"description": "This DB already exist",
|
||||
"code": 409
|
||||
"code": 409,
|
||||
"translation": {
|
||||
"S3": "BucketAlreadyExists"
|
||||
}
|
||||
},
|
||||
"ObjNotFound": {
|
||||
"description": "This object does not exist",
|
||||
"code": 404
|
||||
"code": 404,
|
||||
"translation": {
|
||||
"S3": "NoSuchKey"
|
||||
}
|
||||
},
|
||||
"PermissionDenied": {
|
||||
"description": "Permission denied",
|
||||
"code": 403
|
||||
"code": 403,
|
||||
"translation": {
|
||||
"S3": "PermissionDenied"
|
||||
}
|
||||
},
|
||||
"BadRequest": {
|
||||
"description": "BadRequest",
|
||||
"code": 400
|
||||
"code": 400,
|
||||
"translation": {
|
||||
"S3": "BadRequest"
|
||||
}
|
||||
},
|
||||
"RaftSessionNotLeader": {
|
||||
"description": "NotLeader",
|
||||
"code": 500
|
||||
"code": 500,
|
||||
"translation": {
|
||||
"S3": "RaftSessionNotLeader"
|
||||
}
|
||||
},
|
||||
"RaftSessionLeaderNotConnected": {
|
||||
"description": "RaftSessionLeaderNotConnected",
|
||||
"code": 400
|
||||
"code": 400,
|
||||
"translation": {
|
||||
"S3": "RaftSessionLeaderNotConnected"
|
||||
}
|
||||
},
|
||||
"NoLeaderForDB": {
|
||||
"description": "NoLeaderForDB",
|
||||
"code": 400
|
||||
"code": 400,
|
||||
"translation": {
|
||||
"S3": "NoLeaderForDB"
|
||||
}
|
||||
},
|
||||
"RouteNotFound": {
|
||||
"description": "RouteNotFound",
|
||||
"code": 404
|
||||
"code": 404,
|
||||
"translation": {
|
||||
"S3": "RouteNotFound"
|
||||
}
|
||||
},
|
||||
"NoMapsInConfig": {
|
||||
"description": "NoMapsInConfig",
|
||||
"code": 404
|
||||
"code": 404,
|
||||
"translation": {
|
||||
"S3": "NoMapsInConfig"
|
||||
}
|
||||
},
|
||||
"DBAPINotReady": {
|
||||
"message": "DBAPINotReady",
|
||||
"code": 500
|
||||
"code": 500,
|
||||
"translation": {
|
||||
"S3": "DBAPINotReady"
|
||||
}
|
||||
},
|
||||
"NotEnoughMapsInConfig:": {
|
||||
"description": "NotEnoughMapsInConfig",
|
||||
"code": 400
|
||||
"code": 400,
|
||||
"translation": {
|
||||
"S3": "NotEnoughMapsInConfig:"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,23 @@
|
|||
'use strict'; // eslint-disable-line strict
|
||||
|
||||
const errors = {};
|
||||
|
||||
class ArsenalError extends Error {
|
||||
constructor(type, code, desc) {
|
||||
constructor(type, code, desc, translation) {
|
||||
super(type);
|
||||
this.code = code;
|
||||
this.description = desc;
|
||||
this[type] = true;
|
||||
this.translation = translation;
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate errors to S3
|
||||
* @returns {Object.<ArsenalError>} - the instance of the S3 corresponding
|
||||
* error
|
||||
*/
|
||||
toS3() {
|
||||
return this.translation ? errors[this.translation.S3] : this;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,14 +28,13 @@ class ArsenalError extends Error {
|
|||
* instances
|
||||
*/
|
||||
function errorsGen() {
|
||||
const errors = {};
|
||||
const errorsObj = require('../errors/arsenalErrors.json');
|
||||
|
||||
Object.keys(errorsObj)
|
||||
.filter(index => index !== '_comment')
|
||||
.forEach(index => {
|
||||
errors[index] = new ArsenalError(index, errorsObj[index].code,
|
||||
errorsObj[index].description);
|
||||
errorsObj[index].description, errorsObj[index].translation);
|
||||
});
|
||||
return errors;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
"main": "index.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/scality/IronMan-Arsenal.git"
|
||||
"url": "git+https://github.com/scality/Arsenal.git"
|
||||
},
|
||||
"contributors": [
|
||||
{ "name": "David Pineau", "email": "" },
|
||||
|
@ -14,15 +14,15 @@
|
|||
],
|
||||
"license": "ISC",
|
||||
"bugs": {
|
||||
"url": "https://github.com/scality/IronMan-Arsenal/issues"
|
||||
"url": "https://github.com/scality/Arsenal/issues"
|
||||
},
|
||||
"homepage": "https://github.com/scality/IronMan-Arsenal#readme",
|
||||
"homepage": "https://github.com/scality/Arsenal#readme",
|
||||
"dependencies": {
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^2.4.0",
|
||||
"eslint-config-airbnb": "^6.0.0",
|
||||
"eslint-config-ironman": "scality/IronMan-Guidelines#rel/1.0",
|
||||
"eslint-config-ironman": "scality/Guidelines#rel/1.1",
|
||||
"level": "^1.3.0",
|
||||
"mocha": "^2.3.3",
|
||||
"temp": "^0.8.3"
|
||||
|
|
|
@ -19,3 +19,21 @@ describe('Runtime errors instance generation', () => {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Error translation', () => {
|
||||
Object.keys(errors).forEach(index => {
|
||||
const err = errors[index].translation ?
|
||||
errors[errors[index].translation.S3].message :
|
||||
errors[index].message;
|
||||
it(`should return the S3 translation of ${errors[index]} (${err})`,
|
||||
done => {
|
||||
if (errors[index].translation) {
|
||||
assert.deepStrictEqual(errors[errors[index].translation.S3],
|
||||
errors[index].toS3());
|
||||
} else {
|
||||
assert.deepStrictEqual(errors[index], errors[index].toS3());
|
||||
}
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue