Adding 403 Exception view to CakePHP application - cakephp

I am trying to throw a 403 (Forbidden error) in my controller. When the exception is thrown, I would like to display the associated view. I was under the assumption that if the error is one of the built in exceptions, this would be pretty easy. I throw the exception like this:
throw new ForbiddenException("You do not have permission to view this page.");
I also created a view called "error403.ctp" in the app/view/Errors folder (it already contained 400 and 500). The problem is that when the error is thrown, it displays the error400.ctp view instead. Do I have to create custom exceptions for a built in error? What am I doing wrong.

From http://book.cakephp.org/2.0/en/development/exceptions.html#exception-renderer
"For all 4xx and 5xx errors the view files error400.ctp and error500.ctp are used respectively."
So you aren't doing anything wrong, that's just the default CakePHP behavior. As to how to change it so that you can have a 403 page separate from the other 4XX errors, see CakePHP 2.0 - How to make custom error pages?

I don't have the exact cake version you are using, so I'll use links to docs of version 2.3, but it should apply to any version 2.x.
If you look at the default ExceptionRenderer construct, you get this from the description
Creates the controller to perform rendering on the error response. If the error is a CakeException it will be converted to either a 400 or a 500 code error depending on the code used to construct the error.
And clear enough, from the code of that function, all errors get mapped to that:
$method = 'error500';
if ($code >= 400 && $code < 500) {
$method = 'error400';
}
You'll have to create a custom Exception Renderer if you want to use other views. Also, keep in mind that when using debug < 1, you'll only get 500 error pages
Captures and handles all unhandled exceptions. Displays helpful framework errors when debug > 1. When debug < 1 a CakeException will render 404 or 500 errors. If an uncaught exception is thrown and it is a type that ExceptionHandler does not know about it will be treated as a 500 error.

Related

How to add additional track in twilio-video?

After updating twilio-video JS SDK (from 1.x to 2.x) I have a problem in adding additional device.
This is example error message - ERROR TypeError: transceiver.sender.replaceTrack(...).then(...).finally is not a function.
If I disable this device i get new error message - ERROR Error: Uncaught (in promise): Error: The [LocalVideoTrack #5: 8da6e8e0-a9c1-473b-9916-484a17f61524] was unpublished.
And if I repeat enable device - is OK.
Below is example publishing track in share additional track method.
this.room
.localParticipant
.publishTrack(this.deviceTracks[type]);
this.deviceTrackShared[type] = true;
Below is example unpublishing track -
this.room
.localParticipant
.unpublishTrack(this.deviceTracks[type]);
this.deviceTrackShared[type] = false;
So, I fixed this issue. I lost a lot of time searching for errors in the code, but I just needed to update zone.js from 0.8.x to 0.9.x. Now it's working fine!

CodenameOne - how to catch HTTP 404 error using Terse REST API

How can I catch an HTTP 404 error using the Terse REST API in CodenameOne? At the moment the default error handler gets this but I would like to display my own message instead. The code I am using is fine if the accountNo exists and I can deal with the resulting JSON, but if not I get the standard error handler displaying the 404 error:
Response<Map> jsonData = Rest.get( URL + "lookup").
jsonContent().
queryParam("account",accountNo).
getAsJsonMap();
This seems to be a mistake in that version of the method. It should fail silently without a UI Dialog. We'll fix it for the next update.
Notice that jsonData should have the error response code within it as jsonData.getResponseCode().

How to validate XML file against XSD schema and list all validation errors

I am validating xml against xsd, when first validation error is encountered its throwing first exception, But, through this approach, we cannot get information about all validation errors in the XML file in a single run. If an XML file has multiple validation errors, then in first run, the exception will be thrown as soon as the first error will be encountered and we do not get to know about remaining errors. To know about the subsequent errors, we need to fix the previous error and validate the file again and again till no exception is thrown.
onException( SchemaValidationException.class )
.handled(true)
.to("file:invalid-data")
from("file:in-data?noop=true")
.to("validator:file:my.xsd")
.to("file:out-data");
Which Apache Camel version are you using? In 2.20, the validation code do handle all the errors after validating:
try {
LOG.trace("Validating {}", source);
validator.validate(source, result);
handler.handleErrors(exchange, schema, result);
} catch (SAXParseException e) {
throw new SchemaValidationException(exchange, schema, Collections.singletonList(e), Collections.<SAXParseException>emptyList(), Collections.<SAXParseException>emptyList());
}
The validation is performed by javax.xml.validation.Validator class, though. Please see this question that has a similar discussion. The docs stated that:
Errors found during the validation is sent to the specified ErrorHandler.
If a document is valid, or if a document contains some errors but none of them were fatal and the ErrorHandler didn't throw any exception, then the method returns normally.
Maybe the errors you are facing are fatal? If it's the case, I think that's out of Camel's component control. :(

Error in requesting track for url for SPTTrack object

I am trying to get SPTTrack object from url using Spotify iOS SKD v10beta.
Somehow, it returns an error, like :
Error Domain=com.spotify.ios-sdk Code=102 "No registered class for type 'artist'" UserInfo=0x7a644700 {NSLocalizedDescription=No registered class for type 'artist'}
Strange thing, that it has worked previously. I have found similar problem in getting the user.
What this error is related to? I have removed/added,linked spotify framework multiple times.
Ideas?
Error occurred because ObjC was not present at Other Linker Flags in frameworks/libraries/targets/project.

mpdf no output and php errors in mpdf.php

I'm trying to generate a pdp file in a cakephp application. Therefore, I use the mpdf library as a vendor. But when I try to make a even very simple output it doesn't work. Then when I use the debug property, it shows php errors in the mpdf.php file.
Here is my source code:
<?php
$mpdf=new mPDF();
$mpdf->WriteHTML('hello');
$mpdf->debug = true;
$mpdf->Output();
exit;
?>
And these are the errors shown in the browser:
Notice (8): Undefined index: BODY [APP\vendors\MPDF54\mpdf.php, line 14242]
Notice (8): Undefined index: BODY>>ID>> [APP\vendors\MPDF54\mpdf.php, line 14288]
Notice (8): Undefined offset: -1 [APP\vendors\MPDF54\mpdf.php, line 14421]
Thank you for your help!
This is not a CakePHP problem but related to the library you're using.
Read about how to use the WriteHTML() method.
http://mpdf1.com/manual/index.php?tid=121
And try passing 2 as the 2nd argument.
$mpdf->WriteHTML('hello', 2);
If this still does not work read the documentation, check the examples there.
This is caused by buggy mpdf code. It depends on error (level "notice") reporting to be switched off (it switches it off itself). But if you handle errors some nonstandard way, it is problem..
I solved it by ignoring errors from mpdf.php file in my custom error handler.
I was using my custom error reporting via set_error_handler();

Resources