protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            var result = await base.SendAsync(request, cancellationToken);

            var hasMediaType = request.Headers.Accept.Any(x => x.MediaType == Constants.MEDIA_TYPE);
            //TODO Add error handling here.
            var statusCode = (int)result.StatusCode;

            if (!hasMediaType || (statusCode >= 400 && statusCode < 500))
            {
                // probably malformed request or not found
                return(result);
            }

            var content = result.Content as ObjectContent;

            if (content?.Value is HttpError error)
            {
                JaError je = new JaError(error);
                je.StatusCode = result.StatusCode;
                request.Properties.Add(Constants.HAS_ERROR, je);
            }

            return(result);
        }
Beispiel #2
0
 public void AddError(JaError error)
 {
     hasError = true;
     this.resources?.Add(error);
 }