private async Task ValidateResponse()

in SampleCPMProject/CpmClient/JarvisCPMClient.cs [109:133]


        private async Task ValidateResponse(HttpResponseMessage response)
        {
            if (!response.IsSuccessStatusCode)
            {
                string message;
                switch (response.StatusCode)
                {
                    case System.Net.HttpStatusCode.BadRequest:
                        message = "Invalid contact point";
                        break;
                    case System.Net.HttpStatusCode.Unauthorized:
                    case System.Net.HttpStatusCode.Forbidden:
                        message = "Unauthorised to call CPM API";
                        break;
                    case System.Net.HttpStatusCode.NotFound:
                        message = "Contact Point not found in CPM";
                        break;
                    default:
                        message = $"An exception ocurred while calling CPM API: {await response.Content.ReadAsStringAsync()}";
                        break;
                }

                throw new ServiceException(message, response.StatusCode);
            }
        }