예제 #1
0
        private T ProcessSingularResponse <T>(IRestResponse <T> response)
            where T : class
        {
            if (!response.IsFaulted)
            {
                return(response.Content);
            }

            else
            {
                if (response.HasException && response.HasRawContent)
                {
                    if (!response.ContentAsRaw.StartsWith("["))
                    {
                        this.WriteError(response.ContentAsJObject().ToString(), ErrorCategory.InvalidResult);
                    }
                    else
                    {
                        foreach (ErrorResultException ere in response.ContentAsJArray().ToObject <ErrorResultCollection>())
                        {
                            this.WriteError(ere, ErrorCategory.SyntaxError);
                        }
                    }
                }

                else if (response.HasException && !response.HasRawContent)
                {
                    this.WriteError(response.Exception, ErrorCategory.InvalidOperation);
                }

                else if (!response.IsValidStatusCode)
                {
                    this.WriteError(new NoSonarrResponseException(), ErrorCategory.ResourceUnavailable);
                }

                else
                {
                    this.WriteError(new HttpStatusException(response.StatusCode), ErrorCategory.InvalidResult);
                }

                return(default);