Core 네트워크/권한 주석 보강
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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'];
|
||||
|
||||
Reference in New Issue
Block a user