-
Couldn't load subscription status.
- Fork 3
Closed
Labels
C-databaseComponents: databaseComponents: databaseD-easyDifficulty: easyDifficulty: easyP-normalPriority: normalPriority: normalT-debtType: code debtType: code debt
Milestone
Description
All repository getters are implemented in the following way:
public async getModifier(key: ModifiersKey): Promise<ModifiersValues> {
try {
return await this.db.get(key);
} catch (e) {
if (e.status === 404) {
throw ApiError.NotFound(`Unable to get "${key}" of modifier level"`);
}
throw e;
}
}That is mean a getter throws an error in case this modifier is not found.
As it turned out such behaviour complicates getters usage code. When we need to use a modifier as a condition we are forced to use try - catch construct twice like here:
try {
modifier =
(await modifiersRepository.getModifier(
'occupancy'
)) as OccupancyRateModifier;
} catch (e) {
if (e.status !== 404) {
throw e;
}
try {
modifier =
(await modifierRepository.getModifier(
'occupancy'
)) as OccupancyRateModifier;
} catch (e) {
if (e.status !== 404) {
throw e;
}
}
} I propose to rewrite the getters implementation to not throw errors. If the getter cannot get the value then just return null. This way using getter in conditions will be much simpler.
Metadata
Metadata
Assignees
Labels
C-databaseComponents: databaseComponents: databaseD-easyDifficulty: easyDifficulty: easyP-normalPriority: normalPriority: normalT-debtType: code debtType: code debt