public async Task StartGame()

in Runtime/Core/ApiGatewayManagement/ApiGateway.cs [46:120]


        public async Task<StartGameResponse> StartGame(StartGameRequest request)
        {
            try
            {
                string latenciesJson = null;

                if (request.RegionLatencies != null)
                {
                    string regionToLatencyMappingJson =
                        JsonConvert.SerializeObject(request.RegionLatencies);

                    latenciesJson =
                        string.Format("{{\"regionToLatencyMapping\":{0}}}", regionToLatencyMappingJson);
                }

                if (!IsValid(request))
                {
                    return Response.Fail(new StartGameResponse
                    {
                        ErrorCode = ErrorCode.InvalidParameters
                    });
                }

                (bool success, string errorCode, string token) =
                    _jwtTokenExpirationCheck.RefreshTokenIfExpired(request, _userIdentity);

                if (!success)
                {
                    return Response.Fail(new StartGameResponse
                    {
                        ErrorCode = errorCode
                    });
                }

                (HttpStatusCode statusCode, string body) response = await _httpWrapper.Post(
                        request.ApiGatewayEndpoint,
                        token,
                        "start_game",
                        latenciesJson
                    );

                if (response.statusCode == HttpStatusCode.Conflict)
                {
                    return Response.Fail(new StartGameResponse
                    {
                        ErrorCode = ErrorCode.ConflictError,
                        ErrorMessage = FormatRequestError(response)
                    });
                }

                if (response.statusCode != HttpStatusCode.Accepted)
                {
                    return Response.Fail(new StartGameResponse
                    {
                        ErrorCode = ErrorCode.ApiGatewayRequestError,
                        ErrorMessage = FormatRequestError(response)
                    });
                }

                return Response.Ok(new StartGameResponse
                {
                    IdToken = token
                });
            }
            catch (Exception ex)
            {
                Logger.LogError(ex, ex.Message);

                return Response.Fail(new StartGameResponse
                {
                    ErrorCode = ErrorCode.UnknownError,
                    ErrorMessage = ex.Message
                });
            }
        }