chore(xo-common): remove build step
This commit is contained in:
parent
aff8ec08ad
commit
395d87d290
@ -1,3 +0,0 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = require('../../@xen-orchestra/babel-config')(require('./package.json'))
|
@ -1 +0,0 @@
|
||||
../../scripts/babel-eslintrc.js
|
@ -1,3 +1,216 @@
|
||||
'use strict'
|
||||
|
||||
module.exports = require('./dist/api-errors')
|
||||
const { BaseError } = require('make-error')
|
||||
const { iteratee } = require('lodash')
|
||||
|
||||
class XoError extends BaseError {
|
||||
constructor({ code, message, data }) {
|
||||
super(message)
|
||||
this.code = code
|
||||
this.data = data
|
||||
}
|
||||
|
||||
toJsonRpcError() {
|
||||
return {
|
||||
message: this.message,
|
||||
code: this.code,
|
||||
data: this.data,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const create = (code, getProps) => {
|
||||
const factory = (...args) => {
|
||||
const props = getProps(...args)
|
||||
props.code = code
|
||||
throw new XoError(props)
|
||||
}
|
||||
factory.is = (error, predicate) => error.code === code && (predicate === undefined || iteratee(predicate)(error.data))
|
||||
|
||||
return factory
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
|
||||
exports.notImplemented = create(0, () => ({
|
||||
message: 'not implemented',
|
||||
}))
|
||||
|
||||
exports.noSuchObject = create(1, (id, type) => ({
|
||||
data: { id, type },
|
||||
message: `no such ${type || 'object'} ${id}`,
|
||||
}))
|
||||
|
||||
exports.unauthorized = create(2, (permission, objectId, objectType) => ({
|
||||
data: {
|
||||
permission,
|
||||
object: {
|
||||
id: objectId,
|
||||
type: objectType,
|
||||
},
|
||||
},
|
||||
message: 'not enough permissions',
|
||||
}))
|
||||
|
||||
exports.invalidCredentials = create(3, () => ({
|
||||
message: 'invalid credentials',
|
||||
}))
|
||||
|
||||
// Deprecated alreadyAuthenticated (4)
|
||||
|
||||
exports.forbiddenOperation = create(5, (operation, reason) => ({
|
||||
data: { operation, reason },
|
||||
message: `forbidden operation: ${operation}`,
|
||||
}))
|
||||
|
||||
// Deprecated GenericError (6)
|
||||
|
||||
exports.noHostsAvailable = create(7, () => ({
|
||||
message: 'no hosts available',
|
||||
}))
|
||||
|
||||
exports.authenticationFailed = create(8, () => ({
|
||||
message: 'authentication failed',
|
||||
}))
|
||||
|
||||
exports.serverUnreachable = create(9, objectId => ({
|
||||
data: {
|
||||
objectId,
|
||||
},
|
||||
message: 'server unreachable',
|
||||
}))
|
||||
|
||||
exports.invalidParameters = create(10, (message, errors) => {
|
||||
if (Array.isArray(message)) {
|
||||
errors = message
|
||||
message = undefined
|
||||
}
|
||||
|
||||
return {
|
||||
data: { errors },
|
||||
message: message || 'invalid parameters',
|
||||
}
|
||||
})
|
||||
|
||||
exports.vmMissingPvDrivers = create(11, ({ vm }) => ({
|
||||
data: {
|
||||
objectId: vm,
|
||||
},
|
||||
message: 'missing PV drivers',
|
||||
}))
|
||||
|
||||
exports.vmIsTemplate = create(12, ({ vm }) => ({
|
||||
data: {
|
||||
objectId: vm,
|
||||
},
|
||||
message: 'VM is a template',
|
||||
}))
|
||||
|
||||
exports.vmBadPowerState = create(13, ({ vm, expected, actual }) => ({
|
||||
data: {
|
||||
objectId: vm,
|
||||
expected,
|
||||
actual,
|
||||
},
|
||||
message: `VM state is ${actual} but should be ${expected}`,
|
||||
}))
|
||||
|
||||
exports.vmLacksFeature = create(14, ({ vm, feature }) => ({
|
||||
data: {
|
||||
objectId: vm,
|
||||
feature,
|
||||
},
|
||||
message: `VM lacks feature ${feature || ''}`,
|
||||
}))
|
||||
|
||||
exports.notSupportedDuringUpgrade = create(15, () => ({
|
||||
message: 'not supported during upgrade',
|
||||
}))
|
||||
|
||||
exports.objectAlreadyExists = create(16, ({ objectId, objectType }) => ({
|
||||
data: {
|
||||
objectId,
|
||||
objectType,
|
||||
},
|
||||
message: `${objectType || 'object'} already exists`,
|
||||
}))
|
||||
|
||||
exports.vdiInUse = create(17, ({ vdi, operation }) => ({
|
||||
data: {
|
||||
objectId: vdi,
|
||||
operation,
|
||||
},
|
||||
message: 'VDI in use',
|
||||
}))
|
||||
|
||||
exports.hostOffline = create(18, ({ host }) => ({
|
||||
data: {
|
||||
objectId: host,
|
||||
},
|
||||
message: 'host offline',
|
||||
}))
|
||||
|
||||
exports.operationBlocked = create(19, ({ objectId, code }) => ({
|
||||
data: {
|
||||
objectId,
|
||||
code,
|
||||
},
|
||||
message: 'operation blocked',
|
||||
}))
|
||||
|
||||
exports.patchPrecheckFailed = create(20, ({ errorType, patch }) => ({
|
||||
data: {
|
||||
objectId: patch,
|
||||
errorType,
|
||||
},
|
||||
message: `patch precheck failed: ${errorType}`,
|
||||
}))
|
||||
|
||||
exports.operationFailed = create(21, ({ objectId, code }) => ({
|
||||
data: {
|
||||
objectId,
|
||||
code,
|
||||
},
|
||||
message: 'operation failed',
|
||||
}))
|
||||
|
||||
exports.missingAuditRecord = create(22, ({ id, nValid }) => ({
|
||||
data: {
|
||||
id,
|
||||
nValid,
|
||||
},
|
||||
message: 'missing record',
|
||||
}))
|
||||
|
||||
exports.alteredAuditRecord = create(23, ({ id, record, nValid }) => ({
|
||||
data: {
|
||||
id,
|
||||
record,
|
||||
nValid,
|
||||
},
|
||||
message: 'altered record',
|
||||
}))
|
||||
|
||||
exports.notEnoughResources = create(24, data => ({
|
||||
data, // [{ resourceSet, resourceType, available, requested }]
|
||||
message: 'not enough resources in resource set',
|
||||
}))
|
||||
|
||||
exports.incorrectState = create(25, ({ actual, expected, object, property }) => ({
|
||||
data: {
|
||||
actual,
|
||||
expected,
|
||||
object,
|
||||
property,
|
||||
},
|
||||
message: 'incorrect state',
|
||||
}))
|
||||
|
||||
exports.featureUnauthorized = create(26, ({ featureCode, currentPlan, minPlan }) => ({
|
||||
data: {
|
||||
featureCode,
|
||||
currentPlan,
|
||||
minPlan,
|
||||
},
|
||||
message: 'feature Unauthorized',
|
||||
}))
|
||||
|
@ -15,10 +15,6 @@
|
||||
"name": "Vates SAS",
|
||||
"url": "https://vates.fr"
|
||||
},
|
||||
"preferGlobal": false,
|
||||
"browserslist": [
|
||||
"> 1%"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
},
|
||||
@ -26,21 +22,7 @@
|
||||
"lodash": "^4.16.6",
|
||||
"make-error": "^1.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.0.0",
|
||||
"@babel/core": "^7.0.0",
|
||||
"@babel/preset-env": "^7.0.0",
|
||||
"babel-plugin-lodash": "^3.3.2",
|
||||
"cross-env": "^7.0.2",
|
||||
"rimraf": "^3.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "cross-env NODE_ENV=production babel --source-maps --out-dir=dist/ src/",
|
||||
"clean": "rimraf dist/",
|
||||
"dev": "cross-env NODE_ENV=development babel --watch --source-maps --out-dir=dist/ src/",
|
||||
"prebuild": "yarn run clean",
|
||||
"predev": "yarn run prebuild",
|
||||
"prepublishOnly": "yarn run build",
|
||||
"postversion": "npm publish"
|
||||
}
|
||||
}
|
||||
|
@ -1,210 +0,0 @@
|
||||
import { BaseError } from 'make-error'
|
||||
import { iteratee } from 'lodash'
|
||||
|
||||
class XoError extends BaseError {
|
||||
constructor({ code, message, data }) {
|
||||
super(message)
|
||||
this.code = code
|
||||
this.data = data
|
||||
}
|
||||
|
||||
toJsonRpcError() {
|
||||
return {
|
||||
message: this.message,
|
||||
code: this.code,
|
||||
data: this.data,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const create = (code, getProps) => {
|
||||
const factory = (...args) => new XoError({ ...getProps(...args), code })
|
||||
factory.is = (error, predicate) => error.code === code && (predicate === undefined || iteratee(predicate)(error.data))
|
||||
|
||||
return factory
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
|
||||
export const notImplemented = create(0, () => ({
|
||||
message: 'not implemented',
|
||||
}))
|
||||
|
||||
export const noSuchObject = create(1, (id, type) => ({
|
||||
data: { id, type },
|
||||
message: `no such ${type || 'object'} ${id}`,
|
||||
}))
|
||||
|
||||
export const unauthorized = create(2, (permission, objectId, objectType) => ({
|
||||
data: {
|
||||
permission,
|
||||
object: {
|
||||
id: objectId,
|
||||
type: objectType,
|
||||
},
|
||||
},
|
||||
message: 'not enough permissions',
|
||||
}))
|
||||
|
||||
export const invalidCredentials = create(3, () => ({
|
||||
message: 'invalid credentials',
|
||||
}))
|
||||
|
||||
// Deprecated alreadyAuthenticated (4)
|
||||
|
||||
export const forbiddenOperation = create(5, (operation, reason) => ({
|
||||
data: { operation, reason },
|
||||
message: `forbidden operation: ${operation}`,
|
||||
}))
|
||||
|
||||
// Deprecated GenericError (6)
|
||||
|
||||
export const noHostsAvailable = create(7, () => ({
|
||||
message: 'no hosts available',
|
||||
}))
|
||||
|
||||
export const authenticationFailed = create(8, () => ({
|
||||
message: 'authentication failed',
|
||||
}))
|
||||
|
||||
export const serverUnreachable = create(9, objectId => ({
|
||||
data: {
|
||||
objectId,
|
||||
},
|
||||
message: 'server unreachable',
|
||||
}))
|
||||
|
||||
export const invalidParameters = create(10, (message, errors) => {
|
||||
if (Array.isArray(message)) {
|
||||
errors = message
|
||||
message = undefined
|
||||
}
|
||||
|
||||
return {
|
||||
data: { errors },
|
||||
message: message || 'invalid parameters',
|
||||
}
|
||||
})
|
||||
|
||||
export const vmMissingPvDrivers = create(11, ({ vm }) => ({
|
||||
data: {
|
||||
objectId: vm,
|
||||
},
|
||||
message: 'missing PV drivers',
|
||||
}))
|
||||
|
||||
export const vmIsTemplate = create(12, ({ vm }) => ({
|
||||
data: {
|
||||
objectId: vm,
|
||||
},
|
||||
message: 'VM is a template',
|
||||
}))
|
||||
|
||||
export const vmBadPowerState = create(13, ({ vm, expected, actual }) => ({
|
||||
data: {
|
||||
objectId: vm,
|
||||
expected,
|
||||
actual,
|
||||
},
|
||||
message: `VM state is ${actual} but should be ${expected}`,
|
||||
}))
|
||||
|
||||
export const vmLacksFeature = create(14, ({ vm, feature }) => ({
|
||||
data: {
|
||||
objectId: vm,
|
||||
feature,
|
||||
},
|
||||
message: `VM lacks feature ${feature || ''}`,
|
||||
}))
|
||||
|
||||
export const notSupportedDuringUpgrade = create(15, () => ({
|
||||
message: 'not supported during upgrade',
|
||||
}))
|
||||
|
||||
export const objectAlreadyExists = create(16, ({ objectId, objectType }) => ({
|
||||
data: {
|
||||
objectId,
|
||||
objectType,
|
||||
},
|
||||
message: `${objectType || 'object'} already exists`,
|
||||
}))
|
||||
|
||||
export const vdiInUse = create(17, ({ vdi, operation }) => ({
|
||||
data: {
|
||||
objectId: vdi,
|
||||
operation,
|
||||
},
|
||||
message: 'VDI in use',
|
||||
}))
|
||||
|
||||
export const hostOffline = create(18, ({ host }) => ({
|
||||
data: {
|
||||
objectId: host,
|
||||
},
|
||||
message: 'host offline',
|
||||
}))
|
||||
|
||||
export const operationBlocked = create(19, ({ objectId, code }) => ({
|
||||
data: {
|
||||
objectId,
|
||||
code,
|
||||
},
|
||||
message: 'operation blocked',
|
||||
}))
|
||||
|
||||
export const patchPrecheckFailed = create(20, ({ errorType, patch }) => ({
|
||||
data: {
|
||||
objectId: patch,
|
||||
errorType,
|
||||
},
|
||||
message: `patch precheck failed: ${errorType}`,
|
||||
}))
|
||||
|
||||
export const operationFailed = create(21, ({ objectId, code }) => ({
|
||||
data: {
|
||||
objectId,
|
||||
code,
|
||||
},
|
||||
message: 'operation failed',
|
||||
}))
|
||||
|
||||
export const missingAuditRecord = create(22, ({ id, nValid }) => ({
|
||||
data: {
|
||||
id,
|
||||
nValid,
|
||||
},
|
||||
message: 'missing record',
|
||||
}))
|
||||
|
||||
export const alteredAuditRecord = create(23, ({ id, record, nValid }) => ({
|
||||
data: {
|
||||
id,
|
||||
record,
|
||||
nValid,
|
||||
},
|
||||
message: 'altered record',
|
||||
}))
|
||||
|
||||
export const notEnoughResources = create(24, data => ({
|
||||
data, // [{ resourceSet, resourceType, available, requested }]
|
||||
message: 'not enough resources in resource set',
|
||||
}))
|
||||
|
||||
export const incorrectState = create(25, ({ actual, expected, object, property }) => ({
|
||||
data: {
|
||||
actual,
|
||||
expected,
|
||||
object,
|
||||
property,
|
||||
},
|
||||
message: 'incorrect state',
|
||||
}))
|
||||
|
||||
export const featureUnauthorized = create(26, ({ featureCode, currentPlan, minPlan }) => ({
|
||||
data: {
|
||||
featureCode,
|
||||
currentPlan,
|
||||
minPlan,
|
||||
},
|
||||
message: 'feature Unauthorized',
|
||||
}))
|
Loading…
Reference in New Issue
Block a user