fix(inscription AM): format NIR Corse + extraction message erreur API
Made-with: Cursor
This commit is contained in:
parent
8636b16659
commit
2fa546e6b7
@ -184,8 +184,20 @@ class AuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final decoded = response.body.isNotEmpty ? jsonDecode(response.body) : null;
|
final decoded = response.body.isNotEmpty ? jsonDecode(response.body) : null;
|
||||||
final message = decoded is Map ? (decoded['message'] as String? ?? decoded['error'] as String?) : null;
|
final message = _extractErrorMessage(decoded, response.statusCode);
|
||||||
throw Exception(message ?? 'Erreur lors de l\'inscription (${response.statusCode})');
|
throw Exception(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Extrait le message d'erreur des réponses NestJS (message string, array, ou objet).
|
||||||
|
static String _extractErrorMessage(dynamic decoded, int statusCode) {
|
||||||
|
const fallback = 'Erreur lors de l\'inscription';
|
||||||
|
if (decoded == null || decoded is! Map) return '$fallback ($statusCode)';
|
||||||
|
final msg = decoded['message'];
|
||||||
|
if (msg == null) return decoded['error'] as String? ?? '$fallback ($statusCode)';
|
||||||
|
if (msg is String) return msg;
|
||||||
|
if (msg is List) return msg.map((e) => e.toString()).join('. ').trim();
|
||||||
|
if (msg is Map && msg['message'] != null) return msg['message'].toString();
|
||||||
|
return '$fallback ($statusCode)';
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Rafraîchit le profil utilisateur depuis l'API
|
/// Rafraîchit le profil utilisateur depuis l'API
|
||||||
|
|||||||
@ -49,15 +49,11 @@ String nirToRaw(String normalized) {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Formate pour affichage : 1 12 34 56 789 012-34 ou 1 12 34 2A 789 012-34
|
/// Formate pour affichage : 1 12 34 56 789 012-34 ou 1 12 34 2A 789 012-34 (Corse).
|
||||||
String formatNir(String raw) {
|
String formatNir(String raw) {
|
||||||
final r = nirToRaw(raw);
|
final r = nirToRaw(raw);
|
||||||
if (r.length < 15) return r;
|
if (r.length < 15) return r;
|
||||||
final dept = r.substring(5, 7);
|
// Même structure pour tous : sexe + année + mois + département + commune + ordre-clé.
|
||||||
final isCorsica = dept == '2A' || dept == '2B';
|
|
||||||
if (isCorsica) {
|
|
||||||
return '${r.substring(0, 5)} ${r.substring(5, 7)} ${r.substring(7, 10)} ${r.substring(10, 13)}-${r.substring(13, 15)}';
|
|
||||||
}
|
|
||||||
return '${r.substring(0, 1)} ${r.substring(1, 3)} ${r.substring(3, 5)} ${r.substring(5, 7)} ${r.substring(7, 10)} ${r.substring(10, 13)}-${r.substring(13, 15)}';
|
return '${r.substring(0, 1)} ${r.substring(1, 3)} ${r.substring(3, 5)} ${r.substring(5, 7)} ${r.substring(7, 10)} ${r.substring(10, 13)}-${r.substring(13, 15)}';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,7 +63,7 @@ bool _isFormatValid(String raw) {
|
|||||||
final dept = raw.substring(5, 7);
|
final dept = raw.substring(5, 7);
|
||||||
final restDigits = raw.substring(0, 5) + (dept == '2A' ? '19' : dept == '2B' ? '18' : dept) + raw.substring(7, 15);
|
final restDigits = raw.substring(0, 5) + (dept == '2A' ? '19' : dept == '2B' ? '18' : dept) + raw.substring(7, 15);
|
||||||
if (!RegExp(r'^[12]\d{12}\d{2}$').hasMatch(restDigits)) return false;
|
if (!RegExp(r'^[12]\d{12}\d{2}$').hasMatch(restDigits)) return false;
|
||||||
return RegExp(r'^[12]\d{4}(?:\d{2}|2A|2B)\d{6}$').hasMatch(raw);
|
return RegExp(r'^[12]\d{4}(?:\d{2}|2A|2B)\d{8}$').hasMatch(raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Calcule la clé de contrôle (97 - (NIR13 mod 97)). Pour 2A→19, 2B→18.
|
/// Calcule la clé de contrôle (97 - (NIR13 mod 97)). Pour 2A→19, 2B→18.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user