Daniel Halan - 42 - Oct 26, 2014

Service Response: HTTP 400/500 -> Result DTO not returned correctly.
When Setting base.Response.StatusCode to 400 and above, or throwing new HttpError(respDTO, 500…) the Response Body is not returning the DTO provided, but always a {“status”:0} -object.

Hi Dan, I’ve improved custom HttpError Response handling in this commit and added tests to show the behavior of each:

https://github.com/ServiceStack/ServiceStack/commit/d87326be04e4af48d10c27166439b5b9135519d8

Note: as the tests above show when throwing a HttpError only the ResponseStatus of the DTO is preserved (which is what’s passed into Error filters, gets injected with StackTrace when enabled, etc).

Setting the ErrorCode on the Response and returning a DTO will serialize the entire DTO.

This change is now on MyGet:
https://github.com/ServiceStack/ServiceStack/wiki/MyGet

Daniel Halan:

Ok, just to clarify the scenario, 
+ On Error,
- Send a non-200 Status Code + Status Message 
- Send custom-Json object with detailed info in body, such as
{ status: 422, error: { code: 20, message: “Invalid parameter xxx” } }

Should setting the Response.DTO or HttpError() work as this?

No, if you’re throwing a HttpError with a DTO only the ResponseStatus property of the DTO is preserved (and gets processed in any registered Error handlers). This is what I tried to say in the previous comment - check the new tests added in the commit which illustrates this behavior. (i.e. Custom property is empty when thrown in HttpError but populated when returned as a DTO).

Daniel Halan:

If I understand correctly,
a) throwing HttpError = DTO not preserved,
b) Setting Response.StatusCode, StatusDescription + Response.Dto = DTO should be preserved

a) just the ResponseStatus of the DTO is preserved
b) yep