Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename vertical to cloud, add failed execution check #4

Merged
merged 2 commits into from
Jun 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions csharp/ExecuteFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static class ExecuteFunction
{
private const string DEV_SECRET_KEY = "PLAYFAB_DEV_SECRET_KEY";
private const string TITLE_ID = "PLAYFAB_TITLE_ID";
private const string VERTICAL_NAME = "PLAYFAB_VERTICAL_NAME";
private const string CLOUD_NAME = "PLAYFAB_CLOUD_NAME";
private static readonly HttpClient httpClient = new HttpClient();
/// <summary>
/// A local implementation of the ExecuteFunction feature. Provides the ability to execute an Azure Function with a local URL with respect to the host
Expand Down Expand Up @@ -153,6 +153,11 @@ await httpClient.PostAsync(uriBuilder.Uri.AbsoluteUri, functionRequestContent))
sw.Stop();
long executionTime = sw.ElapsedMilliseconds;

if (!functionResponseMessage.IsSuccessStatusCode)
{
throw new Exception($"An error occured while executing the target function locally: FunctionName: {execRequest.FunctionName}, HTTP Status Code: {functionResponseMessage.StatusCode}.");
}

// Extract the response content
using (var functionResponseContent = functionResponseMessage.Content)
{
Expand Down Expand Up @@ -224,11 +229,11 @@ private static string GetServerApiUri(string endpoint)
{
sb.Append(title).Append(".");
}
// Append the vertical name if applicable
string vertical = Environment.GetEnvironmentVariable(VERTICAL_NAME, EnvironmentVariableTarget.Process);
if (!string.IsNullOrEmpty(vertical))
// Append the cloud name if applicable
string cloud = Environment.GetEnvironmentVariable(CLOUD_NAME, EnvironmentVariableTarget.Process);
if (!string.IsNullOrEmpty(cloud))
{
sb.Append(vertical).Append(".");
sb.Append(cloud).Append(".");
}
// Append base PF API address
sb.Append("playfabapi.com");
Expand Down