mirror of
https://github.com/rainloreley/shlink-manager.git
synced 2024-11-13 23:05:14 +01:00
29 lines
1.0 KiB
Dart
29 lines
1.0 KiB
Dart
import 'dart:async';
|
|
import 'dart:convert';
|
|
import 'package:dartz/dartz.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import '../ServerManager.dart';
|
|
|
|
FutureOr<Either<ServerHealthResponse, Failure>> API_getServerHealth(String? api_key, String? server_url, String apiVersion) async {
|
|
try {
|
|
final response = await http.get(Uri.parse("${server_url}/rest/v${apiVersion}/health"), headers: {
|
|
"X-Api-Key": api_key ?? "",
|
|
});
|
|
if (response.statusCode == 200) {
|
|
var jsonData = jsonDecode(response.body);
|
|
return left(ServerHealthResponse(status: jsonData["status"], version: jsonData["version"]));
|
|
}
|
|
else {
|
|
try {
|
|
var jsonBody = jsonDecode(response.body);
|
|
return right(ApiFailure(type: jsonBody["type"], detail: jsonBody["detail"], title: jsonBody["title"], status: jsonBody["status"]));
|
|
}
|
|
catch(resErr) {
|
|
return right(RequestFailure(response.statusCode, resErr.toString()));
|
|
}
|
|
}
|
|
}
|
|
catch(reqErr) {
|
|
return right(RequestFailure(0, reqErr.toString()));
|
|
}
|
|
} |