Core 네트워크/권한 주석 보강

This commit is contained in:
JiWoong Sul
2025-09-29 17:46:16 +09:00
parent 89fc296765
commit 242e290722
5 changed files with 22 additions and 2 deletions

View File

@@ -1,5 +1,3 @@
// ignore_for_file: public_member_api_docs
import 'package:dio/dio.dart';
import 'api_error.dart';
@@ -93,6 +91,7 @@ class ApiClient {
);
}
/// Dio 요청을 실행하고 `DioException`을 공통 예외 유형으로 변환한다.
Future<Response<T>> _wrap<T>(Future<Response<T>> Function() request) async {
try {
return await request();

View File

@@ -1,5 +1,6 @@
import 'package:dio/dio.dart';
/// API 호출 실패 유형.
enum ApiErrorCode {
badRequest,
unauthorized,
@@ -12,6 +13,7 @@ enum ApiErrorCode {
unknown,
}
/// API 호출 시 공통으로 던지는 예외 모델.
class ApiException implements Exception {
const ApiException({
required this.code,
@@ -32,9 +34,11 @@ class ApiException implements Exception {
'ApiException(code: $code, statusCode: $statusCode, message: $message)';
}
/// Dio 예외를 [ApiException]으로 변환하는 매퍼.
class ApiErrorMapper {
const ApiErrorMapper();
/// Dio 예외 세부 정보를 분석해 적절한 [ApiException]을 생성한다.
ApiException map(DioException error) {
final status = error.response?.statusCode;
final data = error.response?.data;
@@ -124,6 +128,7 @@ class ApiErrorMapper {
);
}
/// 응답 바디 혹은 Dio 예외 객체에서 사용자용 메시지를 추출한다.
String _resolveMessage(DioException error, dynamic data) {
if (data is Map<String, dynamic>) {
final message = data['message'] ?? data['error'];
@@ -136,6 +141,7 @@ class ApiErrorMapper {
return error.message ?? '요청 처리 중 알 수 없는 오류가 발생했습니다.';
}
/// 422/409 등에서 제공되는 필드별 오류 정보를 추출한다.
Map<String, dynamic>? _extractDetails(dynamic data) {
if (data is Map<String, dynamic>) {
final errors = data['errors'];