Пример #1
0
        private void throwOnErrorStatus(OnHttpError handler, HttpResponseMessage response, string reply)
        {
            if (response.IsSuccessStatusCode)
            {
                return;
            }

            var request    = response.RequestMessage;
            var statusCode = (int)response.StatusCode;

            var requestHeaders =
                from header in request.Headers
                let values = header.Value.Select(value => $"'{value}'")
                             select $"{header.Key}: {string.Join(";", values)}";

            var responseHeaders =
                from header in response.Headers
                let values = header.Value.Select(value => $"'{value}'")
                             select $"{header.Key}: {string.Join(";", values)}";

            var detail = new WebApiExceptionDetail {
                statusCode    = response.StatusCode,
                isSuccessfull = response.IsSuccessStatusCode,
                reason        = response.ReasonPhrase,
                request       = new WebApiExceptionDetail.Request {
                    method  = request.Method.Method,
                    url     = request.RequestUri.ToString(),
                    headers = requestHeaders.ToArray()
                },
                response = new WebApiExceptionDetail.Response {
                    headers = responseHeaders.ToArray(),
                    text    = reply
                }
            };

            handler?.Invoke(detail);

            throw
                new WebApiException($"Bad http status code {statusCode}", detail);
        }
Пример #2
0
        private void onFbError(WebApiExceptionDetail detail)
        {
            var     sb = new StringBuilder("Bad HTTP status while calling GraphApi");
            FbError fb = null;

            try
            {
                fb = detail.response.text.Parse <FbError>();
                sb.Append($"[GraphApi: {fb.error.message}]");
            }
            catch
            {}

            var message = sb.ToString();

            var ex = new WebApiException(message, detail);

            if (fb != null)
            {
                ex.AddDetail("GraphApi", fb);
            }

            throw ex;
        }
Пример #3
0
 public WebApiException(string message, WebApiExceptionDetail detail)
     : base(message)
 {
     Detail       = detail;
     Data[_myKey] = detail;
 }