Responsestatus is needed to get errormessage?

Hi,
when i get an exception in my service or validation it get back an empty repsonse object with null values but not error message. When i added a property called ResponseStatus i got the message.

But do i need to add that property to all my ResponseDTOs?

Also can’t i just retrieve the ResponseError and not an empty Resposne object?

Sorry for stupid questions, i’m quite new to this :smile:

Regards Kristian

This behavior is documented in the Error Handling docs:

Error Response Types

The Error Response that gets returned when an Exception is thrown varies on whether a conventionally-named {RequestDto}Response DTO exists or not.

If it exists:

The {RequestDto}Response is returned, regardless of the service method’s response type. If the {RequestDto}Response DTO has a ResponseStatus property, it is populated otherwise no ResponseStatus will be returned. (If you have decorated the {ResponseDto}Response class and properties with [DataContract]/[DataMember] attributes, then ResponseStatus also needs to be decorated, to get populated).

Otherwise, if it doesn’t:

A generic ErrorResponse gets returned with a populated ResponseStatus property.

The Service Clients transparently handles the different Error Response types, and for schema-less formats like JSON/JSV/etc there’s no actual visible difference between returning a ResponseStatus in a custom or generic ErrorResponse - as they both output the same response on the wire.


Basically if you’re using the RequestName/{RequestName}Resposne convention you need to add a ResponseStatus property so the errors can be populated since when this convention is used your Response DTO is returned and needs a place to populate errors.

Thx, i have read it but i understod i didn’t need the ResponseStatus as a generic ErrorResponse should be returned. But i couldn’t see it. But i will add ResponseStatus to all my response DTOs to be sure.

I’ll try to be clearer, if you use the Response DTO naming convention, i.e.

public class GetCustomer : IReturn<GetCustomerResponse> { ... }
public class GetCustomerResponse {}

Then ServiceStack will return GetCustomerResponse Response DTO for Service Exceptions, so you can control whether or not the Service returns error information by having a ResponseStatus property or not.

Whereas if your Request DTO does not follow the Request / Response naming convention, e.g:

public class GetCustomer : IReturn<CustomerResponse> { ... }
public class CustomerResponse {}

Then errors will be returned in a generic ErrorResponse DTO which does contain a ResponseStatus so it will be returned with the error populated in the ResponseStatus property.