이벤트 개발완료
This commit is contained in:
@@ -64,9 +64,11 @@ class ApiService {
|
||||
// POST 요청
|
||||
Future<dynamic> post(String path, {dynamic data}) async {
|
||||
try {
|
||||
final isForm = data is FormData;
|
||||
final response = await _dio.post(
|
||||
path,
|
||||
data: data ?? {},
|
||||
options: isForm ? Options(contentType: 'multipart/form-data') : null,
|
||||
);
|
||||
return response.data;
|
||||
} on DioException catch (e) {
|
||||
@@ -99,14 +101,35 @@ class ApiService {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
// DELETE 요청 (body 데이터 포함이 필요한 경우 사용)
|
||||
Future<dynamic> deleteWithData(String path, {dynamic data}) async {
|
||||
try {
|
||||
final response = await _dio.delete(path, data: data);
|
||||
return response.data;
|
||||
} on DioException catch (e) {
|
||||
_handleError(e);
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
|
||||
// 에러 처리
|
||||
void _handleError(DioException e) {
|
||||
if (e.response != null) {
|
||||
print('API 에러: ${e.response?.statusCode} - ${e.response?.data}');
|
||||
|
||||
final status = e.response?.statusCode;
|
||||
final dataStr = e.response?.data?.toString() ?? '';
|
||||
|
||||
// 초기 진입 등에서 발생 가능한 EXPECTED 400은 콘솔에 노이즈로 찍지 않음
|
||||
// 예: { error: '클럽 정보가 필요합니다.' }
|
||||
if (status == 400 && (dataStr.contains('클럽 정보가 필요합니다') || dataStr.contains('club'))) {
|
||||
// 무음 처리: 상위 호출부에서 사용자 경험을 고려해 처리함
|
||||
return;
|
||||
}
|
||||
|
||||
print('API 에러: $status - ${e.response?.data}');
|
||||
|
||||
// 401 오류 (인증 실패) 처리
|
||||
if (e.response?.statusCode == 401) {
|
||||
if (status == 401) {
|
||||
print('인증 오류: 토큰이 유효하지 않습니다. 로그아웃 처리합니다.');
|
||||
_handleUnauthorized();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user