Refactor exception usage

This commit is contained in:
Jonas Lochmann
2020-09-28 02:00:00 +02:00
parent d68b425e0e
commit 8d65c5d777
148 changed files with 2061 additions and 769 deletions
+9 -10
View File
@@ -15,9 +15,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { uniq } from 'lodash'
import { assertIdWithinFamily } from '../util/token'
import { ParentAction } from './basetypes'
import { assertIdWithinFamily, assertNonEmptyListWithoutDuplicates } from './meta/util'
const actionType = 'UpdateCategorySortingAction'
export class UpdateCategorySortingAction extends ParentAction {
readonly categoryIds: Array<string>
@@ -27,15 +28,13 @@ export class UpdateCategorySortingAction extends ParentAction {
}) {
super()
if (categoryIds.length === 0) {
throw new Error('empty category sorting list')
}
assertNonEmptyListWithoutDuplicates({ actionType, field: 'categoryIds', list: categoryIds })
if (uniq(categoryIds).length !== categoryIds.length) {
throw new Error('category sorting list has duplicates')
}
categoryIds.forEach((categoryId) => assertIdWithinFamily(categoryId))
categoryIds.forEach((categoryId) => assertIdWithinFamily({
actionType,
field: 'categoryIds',
value: categoryId
}))
this.categoryIds = categoryIds
}