protected override async Task ThrowApiExceptionAsync(HttpResponseMessage response)
        {
            var responseData = await response.Content.ReadAsStringAsync();

            var isServerError = (int)response.StatusCode >= 500;

            if (isServerError)
            {
                throw new ServiceUnavailableException(responseData);
            }

            if (response.Headers.Contains("Token-Expired"))
            {
                throw new TokenExpiredException();
            }

            try
            {
                var errorData = responseData.DeserializeJson <ApiErrorData>();
                throw new ConcreteApiException(response, errorData);
            }
            catch (SerializationException serializeEx)
            {
                var errCode    = response.StatusCode.ToString();
                var errMessage = $"{serializeEx.Message}; Api Response: {responseData}";
                var errorData  = new ApiErrorData(errMessage, errCode);

                throw new ConcreteApiException(response, errorData);
            }
        }
Example #2
0
 public ConcreteApiException(HttpResponseMessage response, ApiErrorData errorData)
 {
     this.response  = response;
     this.errorData = errorData;
 }