joukevandermaas / saule

JSON API library for ASP.Net Web API 2.
https://joukevandermaas.github.io/saule
MIT License
76 stars 37 forks source link

Saule returns 500 Internal Server Error when request is not following JSON API format #133

Closed wojciechrak closed 7 years ago

wojciechrak commented 7 years ago

Request

POST /api/v1/articles HTTP/1.1
Host: localhost:8080
Accept: application/vnd.api+json
Content-Type: application/vnd.api+json

{
    "id": 123,
    "name": "test"
}

Response Status 500 Internal Server Error

{
  "errors": [
    {
      "title": "You must add a [ReturnsResourceAttribute] to action methods.",
      "detail": "Saule.JsonApiException: You must add a [ReturnsResourceAttribute] to action methods.",
      "code": "Saule.JsonApiException",
      "links": {
        "about": "https://github.com/joukevandermaas/saule/wiki"
      }
    }
  ]
}

I just spent fair amount of time scratching my head why Saule doesn't respect my [ReturnsResource] attribute on Controller.

But it turns out, that problem is in completely different place. Of course request body is wrong.

Error message is not only not helpful, but very misleading! Shouldn't 400 or 406 be returned instead?

joukevandermaas commented 7 years ago

Yeah, this is pretty terrible. Nice errors are important.

joukevandermaas commented 7 years ago

I published a new pre-release that fixes this problem. I'll try publish a stable release sometime soon.

wojciechrak commented 7 years ago

Great, I will try check this out today.