FlurlHttpException helper creator
See original GitHub issueI 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.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:10 (5 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I did sort of a minimal fix for this - allowing you to do this without any issues:
A
FlurlHttpException
would never be created without a non-nullFlurlCall
within the library, so I didn’t really want to “encourage” this by providing an empty constructor, but hopefully this is a good compromise.I ran into this issue also. I was trying to do
new FlurlHttpException(new FlurlCall());
in a Moq setup and got the same exception