Ejemplo n.º 1
0
        /// <summary>
        /// Creates a suitable exception for an HTTP response, attempting to parse the body as
        /// JSON but falling back to just using the text as the message.
        /// </summary>
        internal static async Task <GoogleApiException> ExceptionForResponseAsync(
            IClientService service,
            HttpResponseMessage response)
        {
            // If we can't even read the response, let that excpetion bubble up, just as it would have done
            // if the error had been occurred when sending the request.
            string responseText = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            RequestError parsedError = null;
            string       message     = responseText;

            try
            {
                parsedError = service.Serializer.Deserialize <StandardResponse <object> >(responseText).Error;
                if (parsedError != null)
                {
                    message = parsedError.ToString();
                }
            }
            catch (JsonException)
            {
                // Just make do with a null RequestError, and the response text set to the body of the response.
                // The contents of the caught exception aren't particularly useful - we don't need to include it
                // as a cause, for example. The expectation is that the exception returned by this method (below)
                // will be thrown by the caller.
            }
            return(new GoogleApiException(service.Name, message)
            {
                Error = parsedError,
                HttpStatusCode = response.StatusCode
            });
        }
Ejemplo n.º 2
0
 private static string PickMessage(RequestError error, Exception inner)
 {
     if (error != null)
     {
         return(error.ToString());
     }
     if (inner != null)
     {
         return(inner.Message);
     }
     return("An error has ocurred, but no message is available.");
 }
Ejemplo n.º 3
0
 private static FirebaseException CreateExceptionFor(RequestError requestError)
 {
     return(new FirebaseException(requestError.ToString()));
 }
Ejemplo n.º 4
0
 private void LoadCompletionHandler(RequestError error)
 {
     if (error != null)
     {
         OnRewardedVideoAdFailedToLoad?.Invoke(_rewardedAd.AdUnitId, new AdMobErrorEventArgs()
         {
             Code = (int?)error?.Code, Domain = error?.Domain, Message = error?.LocalizedDescription, FullStacktrace = error?.ToString()
         });
     }
     else
     {
         OnRewardedVideoAdLoaded?.Invoke(_rewardedAd.AdUnitId, null);
     }
 }