getCurrentUserProfile method
Asynchronously gets the CARP profile of the current user.
Implementation
Future<CarpUser> getCurrentUserProfile() async {
if (currentUser == null || !currentUser!.isAuthenticated)
throw CarpServiceException(message: 'No user is authenticated.');
http.Response response = await httpr
.get(Uri.encodeFull('$userEndpointUri/current'), headers: headers);
int httpStatusCode = response.statusCode;
Map<String, dynamic> responseJson = json.decode(response.body);
if (httpStatusCode == HttpStatus.ok) {
return _currentUser!
..id = responseJson['id']
..accountId = responseJson['accountId']
..isActivated = responseJson['isActivated'] as bool?
..firstName = responseJson['firstName']
..lastName = responseJson['lastName'];
}
// All other cases are treated as an error.
throw CarpServiceException(
httpStatus: HTTPStatus(httpStatusCode, response.reasonPhrase),
message: responseJson["error_description"],
);
}