I have created an Zend AMF service using the FlashBuilder tools. What I wanted to try was to change one of those automatically created methods to throw an exception in order to see the behaviour. Instead of the exception being serialized back to my Flex app it gives me the following:
[RPC Fault faultString="Channel disconnected" faultCode="Client.Error.DeliveryInDoubt" faultDetail="Channel disconnected before an acknowledgement was received"]
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::faultHandler()[E:\dev\4.0.0\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:345]
at mx.rpc::Responder/fault()[E:\dev\4.0.0\frameworks\projects\rpc\src\mx\rpc\Responder.as:68]
at mx.rpc::AsyncRequest/fault()[E:\dev\4.0.0\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:113]
at NetConnectionMessageResponder/channelDisconnectHandler()[E:\dev\4.0.0\frameworks\projects\rpc\src\mx\messaging\channels\NetConnectionChannel.as:684]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.messaging::Channel/disconnectSuccess()[E:\dev\4.0.0\frameworks\projects\rpc\src\mx\messaging\Channel.as:1214]
at mx.messaging.channels::NetConnectionChannel/internalDisconnect()[E:\dev\4.0.0\frameworks\projects\rpc\src\mx\messaging\channels\NetConnectionChannel.as:175]
at mx.messaging.channels::AMFChannel/internalDisconnect()[E:\dev\4.0.0\frameworks\projects\rpc\src\mx\messaging\channels\AMFChannel.as:355]
at mx.messaging.channels::AMFChannel/statusHandler()[E:\dev\4.0.0\frameworks\projects\rpc\src\mx\messaging\channels\AMFChannel.as:445]
The channel disconnects...
[RPC Fault faultString="Channel disconnected" faultCode="Client.Error.DeliveryInDoubt" faultDetail="Channel disconnected before an acknowledgement was received"]
This is the code:
public function getAllUser() {
$stmt = mysqli_prepare($this->connection, "SELECT * FROM $this->tablename");
$this->throwExceptionOnError();
mysqli_stmt_execute($stmt);
$this->throwExceptionOnError();
$rows = array();
mysqli_stmt_bind_result($stmt, $row->id, $row->user_group_id, $row->username, $row->password, $row->active, $row->activation_key, $row->timezone, $row->created_on, $row->modified_on);
while (mysqli_stmt_fetch($stmt)) {
$row->created_on = new DateTime($row->created_on);
$row->modified_on = new DateTime($row->modified_on);
$rows[] = $row;
$row = new stdClass();
mysqli_stmt_bind_result($stmt, $row->id, $row->user_group_id, $row->username, $row->password, $row->active, $row->activation_key, $row->timezone, $row->created_on, $row->modified_on);
}
mysqli_stmt_free_result($stmt);
mysqli_close($this->connection);
$errorCode = 1;
throw(new Exception('the error message you want', $errorCode));
return $rows;
}
Notice the throw statement:
throw(new Exception('the error message you want', $errorCode));
I really didn't expect this. How can I make it work?
Thank you in advanced!!!
Zend Amf is just a serialization protocol of response types to cast them into the AMF format. No error messages are sent back as they normally have sensitive security information in them. Most other PHP amf serialization do not work this way. If you have an exception you need to catch it and convert it to a standard support response type. Also in any of your code every Try needs a Catch as it is not a control structure even if PHP allows you to get away with it.
If you have configured your endpoint to not be production and just need it for debugging.
require_once 'Zend/Amf/Exception.php';
throw new Zend_Amf_Exception('the error message you want', $errorCode);
Well it does serialize the exception message and code which does the job for us. Partially but does it. I didn't notice that the service component I copied the code from in my question contained an exception handler which would suppress the exception and just disconnect the channel. I removed the exception handler letting the exception bubble up to Zend which in turn send the exception message and message code to the client.
I would like to have the actual exception sent as an AS3 object but what can I say. In this way I would have the properties of the exception serialized also. Unfortunately the same goes for custom exceptions.
Related
I'm running into an exception in C# code intended to set the contents of a WinUI3 Image object. I don't know how to interpret the exception message.
Here's the code:
using var responseStream = await response.Content.ReadAsInputStreamAsync();
var memStream = new InMemoryRandomAccessStream();
await RandomAccessStream.CopyAsync(responseStream, memStream);
memStream.Seek(0);
var retVal = new Image();
var source = new BitmapImage();
// the exception is thrown on the next line
await source.SetSourceAsync( outStream );
retVal.Source = source;
The exception message is
Unspecified error (Error HRESULT E_FAIL has been returned from a call to a COM component.)
What's weird is that calls to this code sometimes succeed and sometimes don't, even when the exact same parameters (which define the Uri that the response stream is derived from) are specified and the exact same response is received.
That suggests there's something in the context of the call that's the problem. The cases that succeed are when the code is called from a viewmodel in a WinUI3 test app. The cases that fail are when the code is called from a custom WinUI3 control I've written.
I thought there might be a "called from the wrong thread" problem but in both the success and failure cases the code is being called from the main UI thread.
Another odd thing is that the code throwing the exception is contained within a try/catch block (not shown for simplicity)...but the catch block doesn't catch the exception. Instead, it gets caught by the unhandled exception handler generated by WinUI3.
Advice on how to proceed with researching what's going wrong -- or potential solutions! -- would be appreciated, thanx.
I wanna return the details of exception with ABP .NET Core, what I noticed is when I go to AbpAuditLogs table and App_Data\Logs logFile they contain the exception in details but when I use below method to return the exception it shows only general exception without any details (500 Internal Server Error)
try{
:
:
:
}
catch (Exception ex)
{
throw new System.ArgumentException(ex.InnerException.Message.ToString(), "original");
}
So, How could I return the specific Exception for the user for Example Email Validation Exception and so on?
Update:
I will explain more to make the question more clear :
The way that I handled the exception is attached with this question above .
The problem is when hitting a request on the service from swagger or Postman always see General Error with status Code 500 without any details and that force me to review the details of the exception from Log File or Log Table , I wanna see the details of the exception (e.g FileNotFoundException ) directly from Swagger or Postman without return back to Log File or AbpAuditLogs Table.
I think User Friendly Exception will work for you.
Because if an exception implements the IUserFriendlyException interface, then ABP does not change it's Message and Details properties and directly send it to the client.
throw new UserFriendlyException(
"Username should be unique!"
);
You can find more information here.
Actually, I found the answer in this question for #Mehdi Daustany .what I did is exactly what #Mehdi Daustany answered, I've added below code :
if (_env.EnvironmentName.ToLower() == "development")
Configuration.Modules.AbpWebCommon().SendAllExceptionsToClients = true;
under ***.Web.Core then the details of exception appeared in the Swagger
services.Configure<AbpExceptionHandlingOptions> (options =>
{
options.SendExceptionsDetailsToClients = true;
});
Above code will configure abp to return all the exception details. Just add it to the configuration.
How to stop exception from showing in zend framework 2 and instead when exception is thrown i want to redirect to 404 page .
Actually when user fires wrong url or some how any query gets executed in a wrong way exception is thrown , so i need to block this exception and instead redirect to any other well designed page . I'm unable to track the the exception point or rather catch the exception or from where exception is generated . I have used this code
You can handle the exceptions in anyway you want after catching it as the following example in which you are catching the exception globally...:
In the onBootstrap method i have attached the following code in Module.php in a function to execute when an event occurs, the following attach a function to be executed when an error (exception) is raised:
public function onBootstrap(MvcEvent $e)
{
$application = $e->getApplication();
$em = $application->getEventManager();
//handle the dispatch error (exception)
$em->attach(\Zend\Mvc\MvcEvent::EVENT_DISPATCH_ERROR, array($this,
'handleError'));
//handle the view render error (exception)
$em->attach(\Zend\Mvc\MvcEvent::EVENT_RENDER_ERROR, array($this,
'handleError'));
}
and then defineed in module.php only the function to handle the error
public function handleError(MvcEvent $e)
{
//get the exception
$exception = $e->getParam('exception');
//...handle the exception... maybe log it and redirect to another page,
//or send an email that an exception occurred...
}
I found this code from stackoverflow only , but it is not working , i mean when i'm passing wrong parameters in url , it is showing " A 404 error occurred
Page not found.
The requested controller was unable to dispatch the request.
Controller:
Front\Controller\Front
No Exception available "
Please i need help on this.
you can turn off exceptions in zf2 by chaining 'display_exceptions' => TRUE to 'display_exceptions' => false, [module/Application/config/module.config.php]
Using Groovy / Grails and log4j is there any way to ensure every exception thrown in the code is logged at error level.
Rather than having to find every catch block and explictly log it?
If not groovy / grails - a java suggestion will suffice.
Thanks
I don't believe there's any way to do this for handled exceptions, but you can do it for unhandled exceptions by adding the following to UrlMappings.groovy
"500"(controller: 'error')
Then create an ErrorController.groovy under grails-app/controllers
class ErrorController {
def index() {
Throwable exception = request?.exception?.cause
log.error 'something bad happened', exception
}
}
I tried using special variable $message described here http://www.symfony-project.org/cookbook/1_2/en/error_templates but it seems this variable isn't defined in symfony 1.4, at least it doesn't contain message passed to exception this way throw new sfException('some message')
Do you know other way to pass this message to error.html.php ?
You'll need to do some custom error handling. We implemented a forward to a custom symfony action ourselves. Be cautious though, this action itself could be triggering an exception too, you need to take that into account.
The following might be a good start. First add a listener for the event, a good place would be ProjectConfiguration.class.php:
$this->dispatcher->connect('application.throw_exception', array('MyClass', 'handleException'));
Using the event handler might suffice for what you want to do with the exception, for example if you just want to mail a stack trace to the admin. We wanted to forward to a custom action to display and process a feedback form. Our event handler looked something like this:
class MyClass {
public static function handleException(sfEvent $event) {
$moduleName = sfConfig::get('sf_error_500_module', 'error');
$actionName = sfConfig::get('sf_error_500_action', 'error500');
sfContext::getInstance()->getRequest()->addRequestParameters(array('exception' => $event->getSubject()));
$event->setReturnValue(true);
sfContext::getInstance()->getController()->forward($moduleName, $actionName);
}
}
You can now configure the module and action to forward to on an exception in settings.yml
all:
.actions:
error_500_module: error
error_500_action: error500
In the action itself you can now do whatever you want with the exception, eg. display the feedback form to contact the administrator. You can get the exception itself by using $request->getParameter('exception')
I think I found a much simpler answer. On Symfony 1.4 $message is indeed not defined, but $exception is (it contains the exception object).
So just echo $exception->message.
Et voilĂ !
I've found another trick to do that - sfContext can be used to pass exception message to error.html.php but custom function have to be used to throw exception. For example:
class myToolkit {
public static function throwException($message)
{
sfContext::getInstance()->set('error_msg', $message);
throw new sfException($message);
}
than insted of using throw new sfException('some message') you should use myToolkit::throwException('some message')
To display message in error.html.php use <?php echo sfContext::getInstance()->get('error_msg') ?>