-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: Why doesn't RequestExceptionProcessorBehavior support null responses? #1094
Comments
Nothing stops you from implementing your own |
Yes, I know but the intent of the question is to understand from the authors what the purpose of the null check is in the default behavior. |
I don’t think the owner will give you an answer that satisfies you. If I were the owner, I would just say it’s historical reasons. The Exception Handler Behaviors were a community pull request, and it didn’t have any
but this still wouldn’t throw an exception if null was set in the response.
Then, during the C# 9 update, this code was refactored. The person working on it saw that "cannot be null" removed the MediatR/src/MediatR/Pipeline/RequestExceptionProcessorBehavior.cs Lines 52 to 57 in b4e8cf5
However, RequestExceptionHandlerState has Response marked as potentially null :
Which means setting Response to null is a valid value according to the annotation. Therefore, the exception pipeline probably shouldn't throw an exception in this case.
As I see it, this seems like a coincidence: it wasn’t checking for What I would suggest is that you fix the issue, create a test, and submit a pull request describing your use case and why it’s useful. I’m sure it will be accepted. |
RequestExceptionProcessorBehavior.Handle()
doesn't support the ability to return a null response, i.e.:What is the reason for this? There are legitimate use cases where you might want to return a null response when an exception is handled.
The text was updated successfully, but these errors were encountered: