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.

Differences in behavior

See original GitHub issue

Hello again:

I have added your Middleware to an API, but within the API, developers have used the following methods when dealing with 400 errors:

BadRequest()
BadRequest("My message")
BadRequest(new Exception("Regular exception"))
BadRequest(new ArgumentException("The argument is invalid", nameof(myParameter)))
BadRequest(new ArgumentNullException(nameof(statusCode), "The argument is null"))

I have a console app that I’m using to test what I get back from our controllers using your Middleware. I am getting different things back for the scenarios above, but I’m not sure if the issue is in the Middleware or in how I’m processing the response. For example, the first style, just returning BadRequest() with no message gives me what I expect: a ProblemDetails object in JSON. However, using BadRequest("My message") returns only the value “My message” in the response content, so any of my code that expects to deserialize a ProblemDetails object is failing.

BadRequest(new Exception("Regular exception")) gives back response content matching the Exception:

{"targetSite":null,"stackTrace":null,"message":"Regular exception","data":{},"innerException":null,"helpLink":null,"source":null,"hResult":-2146233088}

When I deserialize this to ProblemDetails, all the properties of the object are Null, except for the Extensions property which now has eight entries, representing the eight items in the content string above. The other BadRequest items behave similarly, but with added Extension entries for the parameter name.

I would like these situations to behave the same way, e.g., Any BadRequest comes back as deserializable response content, (including the message in the BadRequest) without having to overhaul my APIs. Is that possible? Should I be using exceptions inside my BadRequests, or just messages? Do I need a custom ProblemDetails or should I be able to use the default? Are there any options I need to set?

Ultimately, I would like to be able to use your middleware without having to alter my APIs, like changing the BadRequest("My message") style returns to BadRequest(new ProblemDetails()) calls.

I appreciate any help you can offer.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:27 (15 by maintainers)

github_iconTop GitHub Comments

1reaction
speterson-zollcommented, Mar 18, 2021

I figured it out. The call to UseProblemDetails has to come after the call to UseDeveloperExceptionPage. This now works, e.g., I get a proper ProblemDetails instance:

if (env.IsEnvironment(Environments.Development))
{
  app.UseDeveloperExceptionPage();
}

app.UseProblemDetails();
0reactions
speterson-zollcommented, Mar 22, 2021

I asked the question above in [#123]

Read more comments on GitHub >

github_iconTop Results From Across the Web

Individual Differences, Intelligence, and Behavior Analysis
In addition to general intelligence, we discuss three other major aspects of behavior in which individuals differ: speed of processing, working memory, and...
Read more >
Individual Differences and Behavior Genetics | Psychology
Investigators of individual differences attempt to measure, predict, modify, and understand the causal influences on traits that are relatively stable over time ...
Read more >
Behavior Due to Individual Differences
What are individual differences?- They are styles or ways of interacting with the world and the people within it that are unique to...
Read more >
Individual differences in behaviour explain variation ...
Individual variation in behaviour is predicted to be related to differences in individual fitness components such as survival and longevity.
Read more >
Personality, Individual Differences, and Behavior Genetics (PIB)
The PIB program reflects the long tradition of personality, individual differences, and behavioral genetic research at the University. A wide range of ...
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