When I have an exception in my code I want to return it as a FaultException/WebFaultException depending on if it is REST or SOAP. The following problem is with a REST component of my project. The Exception is triggered, I see it in my debug window (see picture).
We clearly see that the WebFaultException is being triggered, but my response in JSON is not a http badrequest nor is my exception message there, but always the following:
{"readyState":4,"responseText":"","status":202,"statusText":"Accepted"}
Here is my interface:
[WebInvoke(Method = "POST", UriTemplate = "/Package/", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
[FaultContract(typeof(FaultException))]
[OperationContract]
string CopyZip(Stream zippedPackage);
Here is its implementation:
public string CopyZip(Stream zippedPackage)
{
try
{
ZipCreator pck = new ZipCreator();
pck.CopyUploadedZip(zippedPackage);
return "Zipped";
}
catch (Exception ex)
{
//throw new FaultException(ex.Message);
throw new WebFaultException<string>(ex.Message, HttpStatusCode.BadRequest);
}
}