Reputation: 2051
Using the ServiceRunner, for exception handling, with the EndConfig.ReturnsInnerException=true,
I expected that the service would return to client the inner exception (original exception),
instead of a WebServiceException (with only the name of inner exception in the errorCode string).
During debugging, in the overriden HandleException,
I could see that the EndConfig.ReturnsInnerException is actually true.
but the client does not get the inner exception. How I can solve this problem ?
It is important, the client to get the inner exception.
UPDATE 2
I send information for the inner exception, by the following way.
( I would prefer the WebServiceException' inner exception to have a reference to my exception. )
class MyServiceRunner<T> : ServiceRunner<T>
{
public override object HandleException(IRequestContext requestContext, T request,
Exception ex)
{
myException myex=ex as myException;
if (myex != null)
{
ResponseStatus rs = new ResponseStatus("APIException", myex.message);
rs.Errors = new List<ResponseError>();
rs.Errors.Add(new ResponseError());
rs.Errors[0].ErrorCode = myex.errorCode;
rs.Errors[0].FieldName = requestContext.PathInfo;
var errorResponse = DtoUtils.CreateErrorResponse(request, ex, rs);
// log the error if I want .... Log.Error("your_message", ex);
// as I don't call the base.HandleException, which log the errors.
return errorResponse;
}
else
return base.HandleException(request, requestDto, ex);
}
}
In client
catch (WebServiceException err)
{
if (err.ErrorCode == "APIException" && err.ResponseStatus.Errors != null )
{
string detailerror =err.ResponseStatus.Errors[0].ErrorCode;
string module = err.ResponseStatus.Errors[0].FieldName;
}
}
Upvotes: 2
Views: 393
Reputation: 1368
Looking at the source code, ServiceRunner.HandleException calls DtoUtils.HandleException. That method is the only one that consumes the ReturnsInnerException setting. It uses it ReturnsInnerException to decide whether to use the given exception for a ResponseStatus object, or the exception's inner one. There is no mechanism in ServiceStack that I can find that returns an inner exception. It only returns ResponseStatus objects.
I'm trying to return an inner exception as well, and I'm going to have to use the Errors list to contain the details just like you did.
Upvotes: 2