question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FlurlHttpException helper creator

See original GitHub issue

I found it hard to create an instance FlurHttpException for my unit tests. Took me a while to create a helper function for it. It would be nice to have some built-in way in the library to create this. Or maybe there is a better way of doing this that I missed.

 public static class UnitTestHelper
    {
        public static FlurlHttpException CreateFlurlHttpException(string httpContent = null, HttpStatusCode statusCode = HttpStatusCode.BadRequest)
        {
            var response = new HttpResponseMessage
            {
                StatusCode = statusCode,
                Content = new StringContent(httpContent ?? string.Empty)
            };
            return new FlurlHttpException
            (new Fixture().Build<FlurlCall>()
                .OmitAutoProperties()
                .With(a => a.Request, new FlurlRequest {Url = "http://dummy"})
                .With(a => a.HttpRequestMessage, new HttpRequestMessage())
                .With(a => a.HttpResponseMessage, response)
                .With(a => a.Response, new FlurlResponse(response))
                .Create());
        }
    }

I created a demo project for sample usage. I’m using AutoFixture by the way for creating this helper.

https://github.com/francischie/FlurlHttpClientExceptionDemo/blob/main/FlurlHttpClientExceptionDemo.Tests/Services/SampleServiceTests.cs

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
tmeniercommented, Dec 14, 2020

I did sort of a minimal fix for this - allowing you to do this without any issues:

new FlurlHttpException(null);

A FlurlHttpException would never be created without a non-null FlurlCall within the library, so I didn’t really want to “encourage” this by providing an empty constructor, but hopefully this is a good compromise.

0reactions
phatt-millipscommented, Aug 9, 2023

I ran into this issue also. I was trying to do new FlurlHttpException(new FlurlCall()); in a Moq setup and got the same exception

Read more comments on GitHub >

github_iconTop Results From Across the Web

Flurl.Http custom error
For the FlurlHttpException case, I do a continuation for ReadAsStringAsync where I declare the continuation to return a User, but inside the ...
Read more >
Error Handling
For simple logging and debugging, FlurlHttpException.Message gives you a handy summary of the error, including the URL, HTTP verb, and status code received....
Read more >
Doney Mathew's Post
NET CORE(5.0/6.0) API on Linux (Ubuntu — EC2 on AWS) — Part 2 ... Not Found response, Flurl throws a FlurlHttpException with the...
Read more >
Doney Mathew's Post
Create pipelines for publishing Nuget Packages with an auto incrementing semantic ... Flurl throws a FlurlHttpException with the appropriate error message.
Read more >
Top 23 rest-client Open-Source Projects (Jun 2023)
Which are the best open-source rest-client projects? This list will help you: ✓openapi-generator, ✓resty, ✓vscode-restclient, ✓autorest, ✓Flurl, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found