public async Task <IActionResult> FinishSession([FromBody] FinishRequest request)
        {
            try
            {
                using (_logger.BeginScope(nameof(FinishSession)))
                {
                    if (request.SessionId == null)
                    {
                        _logger.LogError("Attempted to finish session with null sessionId");
                        return(BadRequest(new
                        {
                            message = "Error: Session ID is empty"
                        }));
                    }

                    var user = await _userManager.GetUserAsync(HttpContext.User);

                    var userId = await _userManager.GetUserIdAsync(user);

                    var session = _sessionRepository.GetLastSessionForUser(int.Parse(userId));

                    if (session.SessionID != request.SessionId)
                    {
                        _logger.LogCritical("User {0}: Obtained session ID is incorrect or malformed.", userId);
                        return(BadRequest(new
                        {
                            message = "Error: Authentification failure. Your session ID is incorrect of malformed."
                        }));
                    }

                    string errorMessage;
                    if (_sessionValidator.IsFinishedSession(session, out errorMessage))
                    {
                        _logger.LogWarning("{0} for user {1}", errorMessage, userId);
                        return(StatusCode(409, errorMessage));
                    }

                    _sessionTracker.CloseSession(session.SessionID);
                    return(Ok());
                }
            }
            catch (Exception e)
            {
                _logger.LogCritical(e.Message);
                _logger.LogTrace(e.StackTrace);
                return(BadRequest(new
                {
                    message = e.Message
                }));
            }
        }