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
+20 -5
View File
@@ -15,8 +15,11 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
import { assertIdWithinFamily } from '../util/token'
import { AppLogicAction } from './basetypes'
import { InvalidActionParameterException } from './meta/exception'
import { assertIdWithinFamily } from './meta/util'
const actionType = 'AddUsedTimeAction'
export class AddUsedTimeAction extends AppLogicAction {
readonly categoryId: string
@@ -32,18 +35,30 @@ export class AddUsedTimeAction extends AppLogicAction {
}) {
super()
assertIdWithinFamily(categoryId)
assertIdWithinFamily({ actionType, field: 'categoryId', value: categoryId })
if (dayOfEpoch < 0 || (!Number.isSafeInteger(dayOfEpoch))) {
throw new Error('illegal dayOfEpoch')
throw new InvalidActionParameterException({
actionType,
staticMessage: 'invalid dayOfEpoch',
dynamicMessage: 'invalid dayOfEpoch: ' + dayOfEpoch
})
}
if (timeToAdd < 0 || (!Number.isSafeInteger(timeToAdd))) {
throw new Error('illegal timeToAdd')
throw new InvalidActionParameterException({
actionType,
staticMessage: 'illegal timeToAdd',
dynamicMessage: 'illegal timeToAdd: ' + timeToAdd
})
}
if (extraTimeToSubtract < 0 || (!Number.isSafeInteger(extraTimeToSubtract))) {
throw new Error('illegal extra time to subtract')
throw new InvalidActionParameterException({
actionType,
staticMessage: 'illegal extra time to subtract',
dynamicMessage: 'illegal extra time to subtract: ' + extraTimeToSubtract
})
}
this.categoryId = categoryId