feat(xo-common/api-errors): notEnoughResources error (#4952)

This commit is contained in:
Pierre Donias
2020-04-27 16:55:44 +02:00
committed by GitHub
parent 9db99ab4a5
commit 5f883f552b
3 changed files with 20 additions and 2 deletions

View File

@@ -11,6 +11,7 @@
- [Internationalization] Italian translation (Thanks [@infodavide](https://github.com/infodavide)!) [#4908](https://github.com/vatesfr/xen-orchestra/issues/4908) (PRs [#4931](https://github.com/vatesfr/xen-orchestra/pull/4931) [#4932](https://github.com/vatesfr/xen-orchestra/pull/4932))
- [Proxy] Associate a license to the deployed proxy (PR [#4912](https://github.com/vatesfr/xen-orchestra/pull/4912))
- Automatic generation of self signed certificate if `autoCert` is not `false` in `xo-server`'s configuration in the corresponding `http.listen` section (PR [#4954](https://github.com/vatesfr/xen-orchestra/pull/4954))
- [Self] Better error when not enough available resources (PR [#4952](https://github.com/vatesfr/xen-orchestra/pull/4952))
### Bug fixes
@@ -40,6 +41,7 @@
>
> In case of conflict, the highest (lowest in previous list) `$version` wins.
- xo-common minor
- @xen-orchestra/self-signed minor
- xo-vmdk-to-vhd patch
- xo-server-audit patch

View File

@@ -197,3 +197,8 @@ export const alteredAuditRecord = create(23, ({ id, record, nValid }) => ({
},
message: 'altered record',
}))
export const notEnoughResources = create(24, data => ({
data, // [{ resourceSet, resourceType, available, requested }]
message: 'not enough resources in resource set',
}))

View File

@@ -11,7 +11,11 @@ import {
remove,
some,
} from 'lodash'
import { noSuchObject, unauthorized } from 'xo-common/api-errors'
import {
noSuchObject,
notEnoughResources,
unauthorized,
} from 'xo-common/api-errors'
import { generateUnsecureToken, lightSet, map, streamToArray } from '../utils'
@@ -315,7 +319,14 @@ export default class {
}
if ((limit.available -= quantity) < 0 && !force) {
throw new Error(`not enough ${id} available in the set ${setId}`)
throw notEnoughResources([
{
resourceSet: setId,
resourceType: id,
available: limit.available + quantity,
requested: quantity,
},
])
}
})
await this._save(set)