Error handling in the new ServiceStack API

I have a simple web service service stack that takes a name as an input parameter. From this thread , I understand that the ResponseStatus property is no longer required when using the new API. But when I tried to compose an unnamed request using a violinist, it returns 400 responses as expected, but does not contain any exception information. Thus, the new API provides a description of errors outside the box specifically for non-.NET clients. If this is not the case, is there a way to provide this information.

public object Any(CustomerRequest request) { if (request.Name == null) { throw new ArgumentException("Name is required"); } var objCustomer = //get customer from DB return objCustomer; } public class CustomerRequest { public string Name {get;set;} public bool IsActive {get;set;} } 
+4
source share
1 answer

You do not need to add ResponseStaus with the new API. According to the penfold example, you should get {"ResponseStatus":{"ErrorCode":"ArgumentException","Message":"Name is required","Errors":[]}} as an answer.

Do you still have a CustomerResponse class in your codebase? If so, try commenting or deleting it. Even if you return object when an exception occurs, ServiceStack will still search for the conditionally named type of response (see here ) and try filling out the ResponseStatus property.

+3
source

All Articles