if (!call.isSuccess()) {
if (call.isMessaging && !(result instanceof ErrorMessage)) {
// Generate proper error result for the Flex messaging client
AbstractMessage request = (AbstractMessage) call.getArguments()[0];
if (result instanceof ServiceNotFoundException) {
ServiceNotFoundException ex = (ServiceNotFoundException) result;
result = FlexMessagingService.returnError(request, "serviceNotAvailable", "Flex messaging not activated", ex.getMessage());
} else if (result instanceof Throwable) {
result = FlexMessagingService.returnError(request, "Server.Invoke.Error", ((Throwable) result).getMessage(), (Throwable) result);
} else {
result = FlexMessagingService.returnError(request, "Server.Invoke.Error", result.toString(), "");
}