public class CreateXXXResponse : IHasResponseStatus
{
public ResponseStatus ResponseStatus { get; set; }
public XXX Result { get; set; }
}
When I there is no Exception, all is returned as a nice json with Result properly rendered.
However, when there is an exception, say BadRequest, the API returns just “BadRequest” plaintext, without any json though ResponseStatus is populated properly - I have put a breakpoint into the class.
What could be the cause?
The app is ASP.NET MVC with ServiceStack running the API.
[Route("/apiversion", "GET")]
public class GetApiVersion : IReturn<GetApiVersionResponse>
{
}
public class GetApiVersionResponse : IHasResponseStatus
{
public ResponseStatus ResponseStatus { get; set; }
public string Version { get; set; }
}
The service is
public class ApiVersionService
{
public object Get(GetApiVersion request)
{
throw new ArgumentException("Wrong Result");
}
}
Your ApiVersionService class should inherit Service but I’m assuming it already does and you’re not providing the exact implementation.
I’m not sure why you’re a plain text ‘Bad Request’ response, as the request is being called from a Browser so you should be seeing a HTML response. I’m assuming you have some other configuration that’s interfering with the response. If you can put a small stand-alone example on GitHub I can investigate further and identify the issue.
The issue is MVC hijacking the Error Responses which happens outside of ServiceStack. Have a look at the Form Hijacking Prevention docs for how you can prevent some errors responses being hijacked.