Skip to content

Create ODataError in Non-Success responses - #2341

Merged
KenitoInc merged 26 commits into
OData:masterfrom
KenitoInc:fix/2331-odata-error-patch
Dec 16, 2020
Merged

Create ODataError in Non-Success responses#2341
KenitoInc merged 26 commits into
OData:masterfrom
KenitoInc:fix/2331-odata-error-patch

Conversation

@KenitoInc

@KenitoInc KenitoInc commented Nov 2, 2020

Copy link
Copy Markdown
Contributor

Issues

This pull request fixes issue #2331 .

Description

When we return error messages from the controller e.g

BadRequest("Error Message");
Conflict("Error Message");
Unauthorized("Error Message");
NotFound("Error Message");

The Error Message is serialized as a string and the response is as follows:

{
  "@odata.context":"https://ServiceUri/odata/$metadata#Edm.String",
  "value":"Error Message"
}

In this PR, we add Custom methods in the ODataController that allows us to Create an ODataError from the Error Message hence the response will be Serialized as an Error to achieve the response below:

{
  "error": {
    "code": "400",
    "message": "Error Message"
  }
}

Checklist (Uncheck if it is not completed)

  • Test cases added
  • Build and test with one-click build and test script passed

Additional work necessary

If documentation update is needed, please add "Docs Needed" label to the issue and provide details about the required document change in the issue.

Comment thread src/Microsoft.AspNetCore.OData/Formatter/ODataOutputFormatter.cs
@xuzhg

xuzhg commented Nov 6, 2020

Copy link
Copy Markdown
Member

@KenitoInc Thanks for your PR, Yes, it's based on our discussion. However, i'd like to re-think it again.
The question is that: "Do we need to provide these method "NotFound(), BadRequest()" at our side? or Can our customer to implement it at customer side?"
I'd like to involve @mikepizzo to share his thought.

Comment thread src/Microsoft.AspNetCore.OData/ODataController.cs Outdated
Comment thread src/Microsoft.AspNetCore.OData/ODataController.cs Outdated
Comment thread src/Microsoft.AspNetCore.OData/Results/BadRequestODataResult.cs Outdated
Comment thread src/Microsoft.AspNetCore.OData/Results/BadRequestODataResult.cs Outdated
Comment thread src/Microsoft.AspNetCore.OData/Results/BadRequestODataResult.cs Outdated
Comment thread src/Microsoft.AspNetCore.OData/Results/BadRequestODataResult.cs Outdated
Comment thread src/Microsoft.AspNetCore.OData/ODataController.cs Outdated
Comment thread test/UnitTest/Microsoft.AspNet.OData.Test.Shared/Formatter/ODataFormatterTests.cs Outdated

@xuzhg xuzhg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕐

Comment thread src/Microsoft.AspNetCore.OData/ODataController.cs Outdated
Comment thread src/Microsoft.AspNetCore.OData/Results/ODataErrorResult.cs Outdated
Comment thread src/Microsoft.AspNetCore.OData/Results/ODataErrorResult.cs Outdated
Comment thread src/Microsoft.AspNetCore.OData/Results/ODataErrorResult.cs Outdated
Comment thread src/Microsoft.AspNetCore.OData/Results/ODataErrorResult.cs Outdated
Comment thread src/Microsoft.AspNetCore.OData/Results/BadRequestODataResult.cs Outdated
Comment thread src/Microsoft.AspNetCore.OData/Results/BadRequestODataResult.cs Outdated
Comment thread src/Microsoft.AspNetCore.OData/Results/BadRequestODataResult.cs Outdated
Comment thread src/Microsoft.AspNetCore.OData/Results/BadRequestODataResult.cs
Comment thread src/Microsoft.AspNetCore.OData/Results/BadRequestODataResult.cs Outdated
Comment thread src/Microsoft.AspNetCore.OData/Results/BadRequestODataResult.cs Outdated
Comment thread src/Microsoft.AspNetCore.OData/Results/BadRequestODataResult.cs
// Arrange
#if NETCORE
const string expectedResponse = "{\"error\":{\"code\":\"400\",\"message\":\"Update failed\"}}";
#else

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need several E2E

Comment thread src/Microsoft.AspNetCore.OData/ODataController.cs Outdated
Comment thread src/Microsoft.AspNetCore.OData/ODataController.cs Outdated
Comment thread src/Microsoft.AspNetCore.OData/ODataController.cs Outdated
Comment thread src/Microsoft.AspNetCore.OData/ODataController.cs
@KenitoInc
KenitoInc marked this pull request as ready for review December 11, 2020 18:30
@KenitoInc
KenitoInc requested a review from xuzhg December 11, 2020 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants