-
Notifications
You must be signed in to change notification settings - Fork 158
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
Create ODataError for non-success responses #623
Conversation
src/Microsoft.AspNetCore.OData/Results/BadRequestODataResult.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.AspNetCore.OData/Results/BadRequestODataResult.cs
Outdated
Show resolved
Hide resolved
test/Microsoft.AspNetCore.OData.E2E.Tests/Commons/TestODataController.cs
Outdated
Show resolved
Hide resolved
test/Microsoft.AspNetCore.OData.E2E.Tests/ODataErrors/ODataErrorsTests.cs
Outdated
Show resolved
Hide resolved
test/Microsoft.AspNetCore.OData.E2E.Tests/ODataErrors/ODataErrorsTests.cs
Outdated
Show resolved
Hide resolved
test/Microsoft.AspNetCore.OData.E2E.Tests/ODataErrors/ODataErrorsTests.cs
Outdated
Show resolved
Hide resolved
test/Microsoft.AspNetCore.OData.E2E.Tests/ODataErrors/ODataErrorsTests.cs
Outdated
Show resolved
Hide resolved
test/Microsoft.AspNetCore.OData.E2E.Tests/ODataErrors/ODataErrorsTests.cs
Outdated
Show resolved
Hide resolved
test/Microsoft.AspNetCore.OData.E2E.Tests/ODataErrors/ODataErrorsTests.cs
Outdated
Show resolved
Hide resolved
test/Microsoft.AspNetCore.OData.E2E.Tests/ODataErrors/ODataErrorsTests.cs
Outdated
Show resolved
Hide resolved
test/Microsoft.AspNetCore.OData.E2E.Tests/ODataErrors/ODataErrorsTests.cs
Outdated
Show resolved
Hide resolved
test/Microsoft.AspNetCore.OData.E2E.Tests/ODataErrors/ODataErrorsTests.cs
Outdated
Show resolved
Hide resolved
test/Microsoft.AspNetCore.OData.Tests/Microsoft.AspNetCore.OData.Tests.csproj
Outdated
Show resolved
Hide resolved
src/Microsoft.AspNetCore.OData/Routing/Controllers/ODataController.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.AspNetCore.OData/Routing/Controllers/ODataController.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.AspNetCore.OData/Routing/Controllers/ODataController.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.AspNetCore.OData/Routing/Controllers/ODataController.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.AspNetCore.OData/Routing/Controllers/ODataController.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.AspNetCore.OData/Routing/Controllers/ODataController.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.AspNetCore.OData/Routing/Controllers/ODataController.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.AspNetCore.OData/Routing/Controllers/ODataController.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.AspNetCore.OData/Routing/Controllers/ODataController.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.AspNetCore.OData/Routing/Controllers/ODataController.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.AspNetCore.OData/Results/UnprocessableEntityODataResult .cs
Outdated
Show resolved
Hide resolved
src/Microsoft.AspNetCore.OData/Results/BadRequestODataResult.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.AspNetCore.OData/Results/BadRequestODataResult.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.AspNetCore.OData/Results/BadRequestODataResult.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.AspNetCore.OData/Results/UnauthorizedODataResult.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.AspNetCore.OData/Results/UnauthorizedODataResult.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.AspNetCore.OData/Results/UnprocessableEntityODataResult .cs
Outdated
Show resolved
Hide resolved
src/Microsoft.AspNetCore.OData/Results/UnprocessableEntityODataResult .cs
Outdated
Show resolved
Hide resolved
src/Microsoft.AspNetCore.OData/Results/UnprocessableEntityODataResult .cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
internal static void ValidateErrorCode(string expectedErrorCode, Microsoft.OData.ODataError error) | ||
{ | ||
if (expectedErrorCode != error.ErrorCode) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
folks, this line looks like creating additional expectation that error.ErrorCode must be the same as HTTP status code, while according to the OData spec, it can be " language-independent string" (see below for more details)
9.4 Error Response Body
The representation of an error response body is format-specific. It consists at least of the following information:
· code: required non-null, non-empty, language-independent string. Its value is a service-defined error code. This code serves as a sub-status for the HTTP error code specified in the response.
· message: required non-null, non-empty, language-dependent, human-readable string describing the error. The Content-Language header MUST contain the language code from [RFC5646] corresponding to the language in which the value for message is written.
· target: optional nullable, potentially empty string indicating the target of the error, for example, the name of the property in error.
· details: optional, potentially empty collection of structured instances with code, message, and target following the rules above.
· innererror: optional structured instance with service-defined content.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is essentially a breaking change! it generates 500 internal server error for this code (suddenly the code that was valid before becomes invalid/not supported)
return NotFound(
new OData.ODataError()
{
ErrorCode = "ErrorEntityNotFound",
Message = "The specified entity was not found."
});
and may prevent clients from upgrading to the latest version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When we return error messages from the controller e.g
The Error Message is serialized as a string and the response is as follows:
In this PR, we add Custom methods in the
ODataController
that allows us to Create anODataError
from the Error Message hence the response will be Serialized as an Error to achieve the response below: