Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

230 common throw custom exception #240

Open
wants to merge 36 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b5e5048
Feat: CustomException 코드를 위한 ExceptionCode enum 클래스 작성 및 적용
hoogom88 Jun 6, 2024
a7483cb
Feat: ExceptionCode enum 클래스 작성
hoogom88 Jun 6, 2024
a01503e
Feat: ExceptionCode 위치관련 오류 코드 추가
hoogom88 Jun 6, 2024
c279620
Feat: GPS 요청 실패에 대한 예외 처리
hoogom88 Jun 6, 2024
6b74005
Merge branch 'dev' into 230-common-throw-custom-exception
hoogom88 Jun 6, 2024
e8b5b75
Feat: NetworkException 수정
hoogom88 Jun 6, 2024
851601f
Feat: Kakao API 요청 예외 처리 수정
hoogom88 Jun 6, 2024
4708466
Feat: 이미지 파일 업로드 예외 처리 수정
hoogom88 Jun 6, 2024
d728ba6
Feat: LocalDailyLocationWeatherDataSourceImpl.getLocalDailyLocationWe…
NalaJang Jun 6, 2024
8784f03
Feat: getDailyLocationWeather() 예외에 따른 분기 처리 적용
NalaJang Jun 6, 2024
8770f92
Feat: LocalFileDataSourceImpl 에 예외 처리 적용
NalaJang Jun 6, 2024
231283c
Feat: ExceptionCode 에 notFoundException 추가
NalaJang Jun 6, 2024
0cda3c6
Merge
NalaJang Jun 6, 2024
794679c
Feat: RemoteFeedDataSourceImpl 커스텀 예외 처리 적용
NalaJang Jun 6, 2024
1eaf05e
Feat: 커스텀 예외 처리 적용으로 변경된 타입 적용
NalaJang Jun 6, 2024
74162b9
Feat: exception code 수정
somarok Jun 6, 2024
be50aa0
Feat: exceptionCode 추가
somarok Jun 6, 2024
59d6783
Feat: dataSource 단 예외처리
somarok Jun 6, 2024
b673c71
Feat: data source 단 예외 처리 추가에 따른 user auth repository 수정
somarok Jun 6, 2024
c942aef
Feat: data source 변경에 따른 일부 view model 수정
somarok Jun 6, 2024
3b41f08
Feat: data source 변경에 따른 일부 테스트 코드 수정
somarok Jun 6, 2024
b9216d9
Merge branch '233-firestore-throw-custom-exception' into 230-common-t…
somarok Jun 6, 2024
2274723
Feat: remote user profile data source 변경에 따른 수정 작업
somarok Jun 6, 2024
7aa79a5
Feat: my page 데이터소스단 변경에 따른 분기 제거
somarok Jun 6, 2024
933ed4e
Feat: ootd post screen & view model 데이터소스단 변경에 따른 분기 제거
somarok Jun 6, 2024
725049b
Feat: app setting screen 데이터소스단 변경에 따른 분기 제거
somarok Jun 6, 2024
fda37f1
Feat: exception 변경에 따른 테스트 코드 수정
somarok Jun 6, 2024
b879d22
Feat: data source 단 변경에 따른 테스트 코드 수정
somarok Jun 7, 2024
a8de72c
Merge branch 'dev' into 230-common-throw-custom-exception
somarok Jun 7, 2024
d436aae
Feat: exception 변경에 따른 테스트 코드 수정
hoogom88 Jun 7, 2024
cd11d3c
Modify: 사용 안하는 import문 제거
SeongJongHo Jun 8, 2024
ddf410a
Refactor: 재할당 안되는 변수 final로 변경
SeongJongHo Jun 8, 2024
35e23df
Refactor: firestore set => update로 변경
SeongJongHo Jun 8, 2024
9d2970c
Refactor: emial 파라미터 인터페이스에 추가
SeongJongHo Jun 8, 2024
f902caa
Feat: transaction에 비동기처리 await 추가
SeongJongHo Jun 8, 2024
b31ced6
Test: 테스트 케이스 제거 및 Mock 데이터 변경
SeongJongHo Jun 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/core/db/transaction_service.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
abstract interface class TransactionService {
Future<bool> run(Function callBack);
Future<void> run(Function callBack);
}
107 changes: 107 additions & 0 deletions lib/core/enum/exception_code.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
enum ExceptionCode implements Exception {
unknownException(
code: '500',
errorMessage: '알 수 없는 오류 발생',
alertMessage: '알 수 없는 오류가 발생했습니다.',
),
internalServerException(
code: '400',
errorMessage: '서버 내부 오류',
alertMessage: '',
),
notFoundException(
code: '404',
errorMessage: '데이터 조회 실패',
alertMessage: '',
),
networkException(
code: '400',
errorMessage: '네트워크 요청 오류',
alertMessage: '네트워크 연결을 확인해주세요.',
),
userNotFoundException(
code: 'user-not-found',
errorMessage: '존재하지 않는 유저입니다.',
alertMessage: '',
),
wrongPasswordException(
code: 'wrong-password',
errorMessage: '비밀번호가 맞지 않습니다.',
alertMessage: '',
),
emailAlreadyInUseException(
code: 'email-already-in-use',
errorMessage: '이미 가입된 이메일입니다.',
alertMessage: '',
),
invalidEmailException(
code: 'invalid-email',
errorMessage: '이메일 형식이 올바르지 못합니다.',
alertMessage: '',
),
weakPasswordException(
code: 'weak-password',
errorMessage: '비밀번호 형식이 안전하지 않습니다.',
alertMessage: '',
),
networkRequestFailedException(
code: 'network-request-failed',
errorMessage: '네트워크가 불안정 합니다.',
alertMessage: '',
),
userDisabledException(
code: 'user-disabled',
errorMessage: '이미 탈퇴한 회원입니다.',
alertMessage: '',
),
invalidCredentialException(
code: 'invalid-credential',
errorMessage: '이메일과 비밀번호를 확인해주세요.',
alertMessage: ''),

authenticationNotExistException(
code: 'authentication-not-exist',
errorMessage: 'FirebaseAuth 로그인 정보 없음',
alertMessage: notShowingMessage),

locationException(
code: 'no-location',
errorMessage: '위치 정보를 가져올 수 없습니다.',
alertMessage: notShowingMessage,
),

kakaoGeoCoderApiException(
code: 'kakao-geo-coder-api-error',
errorMessage: 'Kakao Api 처리 오류',
alertMessage: notShowingMessage,
);

final String code;
final String errorMessage;
final String alertMessage;
static const String notShowingMessage = '';

const ExceptionCode({
required this.code,
required this.alertMessage,
required this.errorMessage,
});

static ExceptionCode fromStatus(String status) {
if (int.tryParse(status) != null) return ExceptionCode.internalServerException;
return switch (status) {
'user-not-found' => ExceptionCode.userNotFoundException,
'wrong-password' => ExceptionCode.wrongPasswordException,
'email-already-in-use' => ExceptionCode.emailAlreadyInUseException,
'invalid-email' => ExceptionCode.invalidEmailException,
'weak-password' => ExceptionCode.weakPasswordException,
'network-request-failed' => ExceptionCode.networkRequestFailedException,
'user-disabled' => ExceptionCode.userDisabledException,
'invaild-credential' => ExceptionCode.invalidCredentialException,
'authentication-not-exist' => ExceptionCode.authenticationNotExistException,
'no-location' => ExceptionCode.locationException,
'kakao-geo-coder-api-error' => ExceptionCode.kakaoGeoCoderApiException,
_ => ExceptionCode.unknownException,
};
}
}
6 changes: 6 additions & 0 deletions lib/core/exception/authentication_exception.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import 'package:weaco/core/exception/custom_business_exception.dart';

class AuthenticationException extends CustomBusinessException {
AuthenticationException(
{required super.code, required super.message});
}
4 changes: 3 additions & 1 deletion lib/core/exception/custom_business_exception.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:weaco/core/enum/exception_code.dart';

/// 어플리케이션 비지니스상 의도한 예외를 정의한 클래스
class CustomBusinessException implements Exception {
final int code;
final ExceptionCode code;
final String message;

CustomBusinessException({required this.code, required this.message});
Expand Down
6 changes: 6 additions & 0 deletions lib/core/exception/location_exception.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import 'package:weaco/core/exception/custom_business_exception.dart';

/// GPS 정보에 접근할 수 없음 예외
class LocationException extends CustomBusinessException {
LocationException({required super.code, required super.message});
}
29 changes: 3 additions & 26 deletions lib/core/exception/network_exception.dart
Original file line number Diff line number Diff line change
@@ -1,28 +1,5 @@
sealed class NetworkException implements Exception {
final String code;
final String message;
import 'package:weaco/core/exception/custom_business_exception.dart';

NetworkException({required this.code, required this.message});

factory NetworkException.noData(
{required String code, required String message}) = NoDataException;

factory NetworkException.errorCode(
{required String code,
required String message}) = ErrorResponseCodeException;

factory NetworkException.unknown(
{required String code, required String message}) = UnknownException;
}

class NoDataException extends NetworkException {
NoDataException({required super.code, required super.message});
}

class ErrorResponseCodeException extends NetworkException {
ErrorResponseCodeException({required super.code, required super.message});
}

class UnknownException extends NetworkException {
UnknownException({required super.code, required super.message});
class NetworkException extends CustomBusinessException {
NetworkException({required super.code, required super.message});
}
4 changes: 2 additions & 2 deletions lib/core/gps/gps_helper.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:developer';
import 'package:geolocator/geolocator.dart';
import 'package:weaco/core/enum/exception_code.dart';
import 'package:weaco/core/gps/gps_permission_status.dart';
import 'package:weaco/core/gps/gps_position.dart';

Expand Down Expand Up @@ -43,7 +44,6 @@ class GpsHelper {
Position position = await Geolocator.getCurrentPosition();
return GpsPosition(lat: position.latitude, lng: position.longitude);
}
// Todo: 커스텀 Exception으로 리팩토링 필요
throw Exception('권한 없음');
throw ExceptionCode.locationException;
}
}
5 changes: 3 additions & 2 deletions lib/data/common/http/status_code_handler.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:weaco/core/enum/exception_code.dart';
import 'package:weaco/core/exception/custom_business_exception.dart';
import 'package:weaco/core/exception/internal_server_exception.dart';

Expand All @@ -7,8 +8,8 @@ import '../../../core/exception/not_found_exception.dart';
CustomBusinessException statusCodeHandler({int? code, String? message}) {
return switch (code) {
404 => NotFoundException(
code: code!, message: message ?? 'Data Not Found Error'),
code: ExceptionCode.unknownException, message: message ?? 'Data Not Found Error'),
_ => InternalServerException(
code: code ?? 500, message: message ?? 'Internal Server Error'),
code: ExceptionCode.internalServerException, message: message ?? 'Internal Server Error'),
};
}
5 changes: 3 additions & 2 deletions lib/data/feed/data_source/remote_feed_data_source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ abstract interface class RemoteFeedDataSource {
/// OOTD 피드 작성 성공 시 : 피드 업로드 요청(Feed) -> / 업로드 완료(bool) ← 파베
/// OOTD 편집 완료 후 [상세 페이지]: 위와 동일.
/// OOTD 편집 완료 후 [마이 페이지]: 위와 동일.*피드 업데이트
Future<bool> saveFeed({

Future<void> saveFeed({
required Transaction transaction,
required Feed feed,
});
Expand All @@ -22,7 +23,7 @@ abstract interface class RemoteFeedDataSource {
});

/// [마이페이지] 피드 삭제: 피드 삭제 요청(id) -> 파베/ 삭제 완료 (bool) from FB
Future<bool> deleteFeed({
Future<void> deleteFeed({
required Transaction transaction,
required String id,
});
Expand Down
Loading