updateSession function
Updates the status of an existing session
@param sessionId - The ID of the session to update @param status - The new status of the session @returns A Future that resolves to the update response @throws UpdateSessionError if the session update fails
Implementation
Future<UpdateSessionResponse> updateSession(
String sessionId, SessionStatus status) async {
logger.info(
'Updating session status for sessionId: $sessionId, new status: ${status.toString()}');
validateFunctionParams([
ParamValidation(input: sessionId, paramName: 'sessionId', isString: true)
], 'updateSession');
try {
final response = await http.post(
Uri.parse('${Constants.BACKEND_BASE_URL}/api/sdk/update/session/'),
headers: {'Content-Type': 'application/json'},
body: jsonEncode({'sessionId': sessionId, 'status': status.name}),
);
final res = jsonDecode(response.body);
if (response.statusCode != 200) {
final errorMessage =
'Error updating session with sessionId: $sessionId. Status Code: ${response.statusCode}';
logger.info('$errorMessage\n$res');
throw updateSessionError(errorMessage);
}
logger
.info('Session status updated successfully for sessionId: $sessionId');
return UpdateSessionResponse(message: res['message']);
} catch (err) {
final errorMessage = 'Failed to update session with sessionId: $sessionId';
logger.info('$errorMessage\n${err.toString()}');
throw updateSessionError(
'Error updating session with sessionId: $sessionId');
}
}