feat(frontend): connect borrow flow to api
This commit is contained in:
@@ -37,6 +37,31 @@ class ApiClient {
|
||||
throw ApiException(_messageErreur(reponse));
|
||||
}
|
||||
|
||||
static Future<dynamic> post(String chemin, Map<String, dynamic> body) async {
|
||||
final uri = Uri.parse("$_baseUrl$chemin");
|
||||
|
||||
late final http.Response reponse;
|
||||
try {
|
||||
reponse = await http.post(
|
||||
uri,
|
||||
headers: const {
|
||||
"content-type": "application/json",
|
||||
"x-user-email": _utilisateurEmail,
|
||||
},
|
||||
body: jsonEncode(body),
|
||||
);
|
||||
} catch (_) {
|
||||
throw const ApiException(
|
||||
"Impossible de joindre le serveur. Vérifiez que le backend est démarré.",
|
||||
);
|
||||
}
|
||||
|
||||
if (reponse.statusCode >= 200 && reponse.statusCode < 300) {
|
||||
return jsonDecode(reponse.body);
|
||||
}
|
||||
throw ApiException(_messageErreur(reponse));
|
||||
}
|
||||
|
||||
static String _messageErreur(http.Response reponse) {
|
||||
try {
|
||||
final corps = jsonDecode(reponse.body);
|
||||
|
||||
Reference in New Issue
Block a user