I was trying to write my own exception handler for CakePHP 2.2 but I totally lost in implementation.
http://book.cakephp.org/2.0/en/development/exceptions.html
So I decided to use MyController::myAction in exceptions. Can you tell me easiest way to redirect users to myAction and parse error type inside action.
According to the documentation you following, it looks you were on the right track.
You can create your own custom controller to handle exception. See this link: http://book.cakephp.org/2.0/en/development/exceptions.html#creating-a-custom-controller-to-handle-exceptions
Related
I'm working on a logging solution where Camel routes are defined at runtime with a Java DSL String. I wonder if there's a way to check programmatically some errors such as components not found in the route. The only option I was able to find is catching the org.apache.camel.ResolveEndpointFailedException and dig into the error message. Is there a better way to validate the route?
Just to give an example, it would be good to ascertain if a route syntax is completely wrong or if just a component wasn't found so that I can output a message e.g. "install ftp component".
You can use Fabric8 Camel Maven Plugin (http://fabric8.io/guide/camelMavenPlugin.html) for validating Camel endpoints in the source code.
Look at this article by Claus Ibsen to get more information : https://blog.fabric8.io/cheers-fabric8-camel-maven-plugin-to-validate-camel-endpoints-from-source-code-8768aff76b41#.wcji8hfdg
I want to create one custom 404 page for all errors coming to the website for production environment. For example if I receive missing controller or view error then it will redirect to
http://example.com/404.html, Also in some cases I will deliberately redirect it http://example.com/404.html
Earlier in CakePHP 2.x it was done by adding following action in AppContoller.php
public function appError($error) {
$this->redirect('/page-not-found.html',301,false);
}
But It is not working in CakePHP 3.x, I want to replicate same behavior in CakePHP 3.x
Do not redirect
The correct action to take if a page should render a 404 is to render a 404.
Redirecting to another page is confusing for users, especially since many browsers cache 301 responses making the original url inaccessible. This also affects e.g. search engines as the static file 404.html will have a 200 response code (unless you modify your webserver config) so it'll say 404 but simply not be.
The blog tutorial, which all devs should do before starting a project, guides you in the right direction:
public function view($id)
{
$article = $this->Articles->get($id);
$this->set(compact('article'));
}
The table method get returns a single entity object or throws an exception:
If the get operation does not find any results a Cake\Datasource\Exception\RecordNotFoundException will be raised. You can either catch this exception yourself, or allow CakePHP to convert it into a 404 error.
The controller code in this example doesn't need to have any "what if it doesn't exist" handling because by default if the record doesn't exist the result is a 404.
Changing the 404 template
If you want to change the way the 404 or 500 pages look change the template files
For all 4xx and 5xx errors the template files error400.ctp and error500.ctp are used respectively.
The error template is in your application, note that in production mode the output is very minimal.
If the get operation does not find any results a Cake\Datasource\Exception\RecordNotFoundException will be raised. You can either catch this exception yourself, or allow CakePHP to convert it into a 404 error.
The simplest way can be just implemented in two steps,
Step 1:
turn the debug mode off in config/app.php
Step 2:
Replace the content of src/Template/Layout/error.ctp with your custom layout.
Google Drive Realtime API has a nice set of errorTypes that you can listen for, so you can handle each case individually:
https://developers.google.com/drive/realtime/reference/gapi.drive.realtime.ErrorType
Unfortunately, this list doesn't include the DocumentClosed error. For some reason, that error is its own object in the API.
https://developers.google.com/drive/realtime/reference/gapi.drive.realtime.DocumentClosedError
For the life of me, I cannot figure out how to handle this error. I have an onError listener function set up on my realtime.load, but that only catches Errors, which are different than the DocumentClosedError.
Is there any way to handle/listen for this particular type of error? I have also tried document.addEventListener but that was a desperate attempt and didn't work
For anyone else wondering about this, it was related to binding between angular and google drive.
The document was closed for google but the angular binding were still there.
We handled this by intercepting the angular error based on this.
http://odetocode.com/blogs/scott/archive/2014/04/21/better-error-handling-in-angularjs.aspx
The DocumentClosedError is a different type of error as it is only thrown when you are accessing an invalid document. The only times that that Realtime Document should be invalid are: 1) after one of the fatal errors defined in ErrorType is handled by your error function, or 2)after you call .close() yourself on the document.
Tracking whether you hit one of these two conditions on the client and ensuring you don't access the Document afterwards is how to prevent the error from firing. Ideally if you get into a state where your document is closed, the app should teardown its references to the realtime models and reconnect to reduce the number places that you will throw exceptions.
TL;DR: If you're hitting DocumentClosedErrors you should change the way that you handle fatal errors defined in ErrorType.
I am referring to the problem that has already been asked. CakePHP 2.0 - How to make custom error pages?
It gives me a lot idea of solving out the problem but instead of thowing exception I want to use it for all of my controller and actions. It suggested me to do where ever at particular location I want throw new NotFoundException(); I want it everywhere I mean where so ever controller or action is missing.
With debug turned off all your error are converted to either 400 or 500 errors. So you just need to customize your app/View/Errors/error400.ctp and app/View/Errors/error500.ctp as required.
Iam trying to store the state in thedb through webservice.
Iam using Http State Provider to do so.
Iam getting an error in the following line saying object expected.
Ext.state.Manager.setProvider(new Ext.state.HttpProvider({ url: 'GetGridState.asmx/readdata' }));
Please help me in this issue.
You should probably use firebug or even alerts if nothing else to see if maybe you're not passing an object where you should be.
Are you using the correct version of ExtJS? It looks like there is no more Ext.state.HttpProvider in ExtJS 3.1.
Sounds like you have not included the HttpStateProvider class code correctly, or included it after the code that is trying to use it. Double-check that if you are referring to an external js file, it is loaded properly and in the right order.