feat: check for correct version
This commit is contained in:
parent
b751d93be6
commit
8e379241ee
6 changed files with 169 additions and 92 deletions
|
|
@ -39,4 +39,8 @@ class AuthRepository extends ChangeNotifier {
|
|||
return Result.error(Exception(e));
|
||||
}
|
||||
}
|
||||
|
||||
Future<Result<int>> getRemoteApiVersion() async {
|
||||
return await _authClient.getRemoteApiVersion();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,4 +66,23 @@ class AuthClient {
|
|||
client.close();
|
||||
}
|
||||
}
|
||||
|
||||
Future<Result<int>> getRemoteApiVersion() async {
|
||||
final client = http.Client();
|
||||
try {
|
||||
final response = await client.get(
|
||||
Uri.parse("https://$apiBasePath/version"),
|
||||
);
|
||||
if (response.statusCode == 200) {
|
||||
final json = jsonDecode(response.body) as int;
|
||||
return Result.ok(json);
|
||||
} else {
|
||||
throw "Something wrong happened";
|
||||
}
|
||||
} catch (e) {
|
||||
return Result.error(Exception(e));
|
||||
} finally {
|
||||
client.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue