EnakPoint & EnakCoin wallet, PIN, outlet, order, community, reward
- Wallet EnakPoint & EnakCoin: beranda, riwayat, saldo kedaluwarsa, kode bayar, tukar EnakCoin, transfer - PIN (buat, ganti, lupa), outlet, riwayat order, game spin - Halaman community, webview, coming soon, dan ikon menu beranda baru - Redesign Reward Saya: kartu tiket, filter chip, detail kode + QR - Hapus customer point loader, menu, dan checkout lama - Base URL ke enaklo-pos-api.altru.id Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
5954510b93
commit
f5e3075205
@@ -17,6 +17,42 @@ class AuthRemoteDataProvider {
|
||||
|
||||
AuthRemoteDataProvider(this._apiClient);
|
||||
|
||||
static const _defaultErrorMessage = 'Terjadi kesalahan coba lagi nanti';
|
||||
|
||||
Map? _firstError(dynamic body) {
|
||||
final errors = body is Map ? body['errors'] : null;
|
||||
if (errors is! List || errors.isEmpty || errors.first is! Map) return null;
|
||||
return errors.first as Map;
|
||||
}
|
||||
|
||||
/// Kode bisa dikirim sebagai string ("304") maupun int (304).
|
||||
String? _errorCode(dynamic body) => _firstError(body)?['code']?.toString();
|
||||
|
||||
/// Pesan untuk error validasi (`303`/`310`) dan aturan bisnis (`304`).
|
||||
String _errorMessage(dynamic body) {
|
||||
final error = _firstError(body);
|
||||
final code = error?['code']?.toString();
|
||||
final cause = error?['cause']?.toString() ?? '';
|
||||
final lower = cause.toLowerCase();
|
||||
|
||||
if (lower.contains('password') &&
|
||||
(lower.contains('min') ||
|
||||
lower.contains('least') ||
|
||||
lower.contains('short'))) {
|
||||
final length = RegExp(r'\d+').firstMatch(cause)?.group(0);
|
||||
return length == null
|
||||
? 'Kata sandi terlalu pendek'
|
||||
: 'Kata sandi minimal $length karakter';
|
||||
}
|
||||
|
||||
if ((code == '303' || code == '304' || code == '310') &&
|
||||
cause.isNotEmpty) {
|
||||
return cause;
|
||||
}
|
||||
|
||||
return _defaultErrorMessage;
|
||||
}
|
||||
|
||||
Future<DC<AuthFailure, CheckPhoneDto>> checkPhone({
|
||||
required String phoneNumber,
|
||||
}) async {
|
||||
@@ -160,33 +196,14 @@ class AuthRemoteDataProvider {
|
||||
);
|
||||
|
||||
if (response.data['success'] == false) {
|
||||
if ((response.data['errors'] as List).isNotEmpty) {
|
||||
if (response.data['errors'][0]['code'] == 900) {
|
||||
return DC.error(
|
||||
AuthFailure.dynamicErrorMessage(
|
||||
'Invalid Registration, Lakukan kembali dari awal',
|
||||
),
|
||||
);
|
||||
} else if (response.data['errors'][0]['code'] == "304") {
|
||||
return DC.error(
|
||||
AuthFailure.dynamicErrorMessage(
|
||||
response.data['errors'][0]['cause'],
|
||||
),
|
||||
);
|
||||
} else {
|
||||
return DC.error(
|
||||
AuthFailure.dynamicErrorMessage(
|
||||
'Terjadi kesalahan coba lagi nanti',
|
||||
),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return DC.error(
|
||||
AuthFailure.dynamicErrorMessage(
|
||||
'Terjadi kesalahan coba lagi nanti',
|
||||
),
|
||||
);
|
||||
}
|
||||
final code = _errorCode(response.data);
|
||||
return DC.error(
|
||||
AuthFailure.dynamicErrorMessage(
|
||||
code == '900'
|
||||
? 'Invalid Registration, Lakukan kembali dari awal'
|
||||
: _errorMessage(response.data),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
final dto = LoginDto.fromJson(response.data['data']);
|
||||
|
||||
Reference in New Issue
Block a user