Skip to content

Commit 422ec2a

Browse files
feat(*): add error handling and reporting
1 parent ab2a217 commit 422ec2a

File tree

67 files changed

+633
-386
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+633
-386
lines changed

lib/application/features/app_usages/commands/add_app_usage_tag_command.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:mediatr/mediatr.dart';
22
import 'package:nanoid2/nanoid2.dart';
33
import 'package:whph/application/features/app_usages/services/abstraction/i_app_usage_tag_repository.dart';
4+
import 'package:whph/core/acore/errors/business_exception.dart';
45
import 'package:whph/domain/features/app_usages/app_usage_tag.dart';
56

67
class AddAppUsageTagCommand implements IRequest<AddAppUsageTagCommandResponse> {
@@ -30,7 +31,7 @@ class AddAppUsageTagCommandHandler implements IRequestHandler<AddAppUsageTagComm
3031
@override
3132
Future<AddAppUsageTagCommandResponse> call(AddAppUsageTagCommand request) async {
3233
if (await _appUsageTagRepository.anyByAppUsageIdAndTagId(request.appUsageId, request.tagId)) {
33-
throw Exception('App usage tag already exists');
34+
throw BusinessException('App usage tag already exists');
3435
}
3536

3637
var appUsageTag = AppUsageTag(

lib/application/features/app_usages/commands/delete_app_usage_command.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:mediatr/mediatr.dart';
22
import 'package:whph/application/features/app_usages/services/abstraction/i_app_usage_repository.dart';
3+
import 'package:whph/core/acore/errors/business_exception.dart';
34
import 'package:whph/domain/features/app_usages/app_usage.dart';
45

56
class DeleteAppUsageCommand implements IRequest<DeleteAppUsageCommandResponse> {
@@ -25,7 +26,7 @@ class DeleteAppUsageCommandHandler implements IRequestHandler<DeleteAppUsageComm
2526
Future<DeleteAppUsageCommandResponse> call(DeleteAppUsageCommand request) async {
2627
AppUsage? appUsage = await _appUsageRepository.getById(request.id);
2728
if (appUsage == null) {
28-
throw Exception('AppUsage with id ${request.id} not found');
29+
throw BusinessException('AppUsage with id ${request.id} not found');
2930
}
3031

3132
await _appUsageRepository.delete(appUsage);

lib/application/features/app_usages/commands/remove_tag_tag_command.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:mediatr/mediatr.dart';
22
import 'package:whph/application/features/app_usages/services/abstraction/i_app_usage_tag_repository.dart';
3+
import 'package:whph/core/acore/errors/business_exception.dart';
34
import 'package:whph/domain/features/app_usages/app_usage_tag.dart';
45

56
class RemoveAppUsageTagCommand implements IRequest<RemoveAppUsageTagCommandResponse> {
@@ -29,7 +30,7 @@ class RemoveAppUsageTagCommandHandler
2930
Future<RemoveAppUsageTagCommandResponse> call(RemoveAppUsageTagCommand request) async {
3031
AppUsageTag? appUsageTag = await _appUsageTagRepository.getById(request.id);
3132
if (appUsageTag == null) {
32-
throw Exception('App usage tag with id ${request.id} not found');
33+
throw BusinessException('App usage tag with id ${request.id} not found');
3334
}
3435
await _appUsageTagRepository.delete(appUsageTag);
3536

lib/application/features/app_usages/commands/save_app_usage_command.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:mediatr/mediatr.dart';
22
import 'package:nanoid2/nanoid2.dart';
33
import 'package:whph/application/features/app_usages/services/abstraction/i_app_usage_repository.dart';
4+
import 'package:whph/core/acore/errors/business_exception.dart';
45
import 'package:whph/domain/features/app_usages/app_usage.dart';
56

67
class SaveAppUsageCommand implements IRequest<SaveAppUsageCommandResponse> {
@@ -48,7 +49,7 @@ class SaveAppUsageCommandHandler implements IRequestHandler<SaveAppUsageCommand,
4849
if (request.id != null) {
4950
appUsage = await _appUsageRepository.getById(request.id!);
5051
if (appUsage == null) {
51-
throw Exception('App Usage with id ${request.id} not found');
52+
throw BusinessException('App Usage with id ${request.id} not found');
5253
}
5354

5455
appUsage.displayName = request.displayName;

lib/application/features/app_usages/queries/get_app_usage_query.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:mediatr/mediatr.dart';
22
import 'package:whph/application/features/app_usages/services/abstraction/i_app_usage_repository.dart';
3+
import 'package:whph/core/acore/errors/business_exception.dart';
34
import 'package:whph/domain/features/app_usages/app_usage.dart';
45

56
class GetAppUsageQuery implements IRequest<GetAppUsageQueryResponse> {
@@ -33,7 +34,7 @@ class GetAppUsageQueryHandler implements IRequestHandler<GetAppUsageQuery, GetAp
3334
request.id,
3435
);
3536
if (appUsages == null) {
36-
throw Exception('AppUsage with id ${request.id} not found');
37+
throw BusinessException('AppUsage with id ${request.id} not found');
3738
}
3839

3940
return GetAppUsageQueryResponse(

lib/application/features/habits/commands/add_habit_tag_command.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:mediatr/mediatr.dart';
22
import 'package:nanoid2/nanoid2.dart';
33
import 'package:whph/application/features/habits/services/i_habit_tags_repository.dart';
4+
import 'package:whph/core/acore/errors/business_exception.dart';
45
import 'package:whph/domain/features/habits/habit_tag.dart';
56

67
class AddHabitTagCommand implements IRequest<AddHabitTagCommandResponse> {
@@ -30,7 +31,7 @@ class AddHabitTagCommandHandler implements IRequestHandler<AddHabitTagCommand, A
3031
@override
3132
Future<AddHabitTagCommandResponse> call(AddHabitTagCommand request) async {
3233
if (await _habitTagRepository.anyByHabitIdAndTagId(request.habitId, request.tagId)) {
33-
throw Exception('Habit tag already exists');
34+
throw BusinessException('Habit tag already exists');
3435
}
3536

3637
var habitTag = HabitTag(

lib/application/features/habits/commands/delete_habit_command.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:mediatr/mediatr.dart';
22
import 'package:whph/application/features/habits/services/i_habit_repository.dart';
3+
import 'package:whph/core/acore/errors/business_exception.dart';
34
import 'package:whph/domain/features/habits/habit.dart';
45

56
class DeleteHabitCommand implements IRequest<DeleteHabitCommandResponse> {
@@ -19,7 +20,7 @@ class DeleteHabitCommandHandler implements IRequestHandler<DeleteHabitCommand, D
1920
Future<DeleteHabitCommandResponse> call(DeleteHabitCommand request) async {
2021
Habit? habit = await _habitRepository.getById(request.id);
2122
if (habit == null) {
22-
throw Exception('Habit with id ${request.id} not found');
23+
throw BusinessException('Habit with id ${request.id} not found');
2324
}
2425

2526
await _habitRepository.delete(habit);

lib/application/features/habits/commands/delete_habit_record_command.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:mediatr/mediatr.dart';
22
import 'package:whph/application/features/habits/services/i_habit_record_repository.dart';
3+
import 'package:whph/core/acore/errors/business_exception.dart';
34
import 'package:whph/domain/features/habits/habit_record.dart';
45

56
class DeleteHabitRecordCommand implements IRequest<DeleteHabitRecordCommandResponse> {
@@ -21,7 +22,7 @@ class DeleteHabitRecordCommandHandler
2122
Future<DeleteHabitRecordCommandResponse> call(DeleteHabitRecordCommand request) async {
2223
HabitRecord? habitRecord = await _habitRecordRepository.getById(request.id);
2324
if (habitRecord == null) {
24-
throw Exception('HabitRecord with id ${request.id} not found');
25+
throw BusinessException('HabitRecord with id ${request.id} not found');
2526
}
2627

2728
await _habitRecordRepository.delete(habitRecord);

lib/application/features/habits/commands/remove_habit_tag_command.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:mediatr/mediatr.dart';
22
import 'package:whph/application/features/habits/services/i_habit_tags_repository.dart';
3+
import 'package:whph/core/acore/errors/business_exception.dart';
34

45
import 'package:whph/domain/features/habits/habit_tag.dart';
56

@@ -29,7 +30,7 @@ class RemoveHabitTagCommandHandler implements IRequestHandler<RemoveHabitTagComm
2930
Future<RemoveHabitTagCommandResponse> call(RemoveHabitTagCommand request) async {
3031
HabitTag? habitTag = await _habitTagRepository.getById(request.id);
3132
if (habitTag == null) {
32-
throw Exception('HabitTag with id ${request.id} not found');
33+
throw BusinessException('HabitTag with id ${request.id} not found');
3334
}
3435
await _habitTagRepository.delete(habitTag);
3536

lib/application/features/habits/commands/save_habit_command.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:mediatr/mediatr.dart';
22
import 'package:nanoid2/nanoid2.dart';
33
import 'package:whph/application/features/habits/services/i_habit_repository.dart';
4+
import 'package:whph/core/acore/errors/business_exception.dart';
45
import 'package:whph/domain/features/habits/habit.dart';
56

67
class SaveHabitCommand implements IRequest<SaveHabitCommandResponse> {
@@ -39,7 +40,7 @@ class SaveHabitCommandHandler implements IRequestHandler<SaveHabitCommand, SaveH
3940
if (request.id != null) {
4041
habit = await _habitRepository.getById(request.id!);
4142
if (habit == null) {
42-
throw Exception('Habit with id ${request.id} not found');
43+
throw BusinessException('Habit with id ${request.id} not found');
4344
}
4445

4546
await _update(habit, request);

0 commit comments

Comments
 (0)