Comments (6)
Hi @pablogupi I'm glad you find the plugin useful. The first thing I would check is your emailLevels configuration key to make sure you have exceptions configured to be handled by the emailer.
'emailLevels' => ['exception', 'error'],
You'll want to make sure at least the exception key is in there (along with keys for any other types of errors you want handled.
Second you'll want to double check and make sure you followed the installation portion of the guide completely. There are two spots where you need to override the base implementation packaged with cakephp.
Specifically make sure you followed these instructions and are overriding the middleware:
In your src/Application.php replace:
use Cake\Error\Middleware\ErrorHandlerMiddleware;
With:
use ErrorEmail\Middleware\ErrorHandlerMiddleware;
If it still doesn't work after those looking through those two things let me know and I can try to get a base install of cake 3.7.7 and make sure they didn't change anything that would prevent it from working.
from cakephp-error-email.
Hi! Thank you very much for the quick answer.
This is my app.php
'ErrorEmail' => [
'email' => true,
'emailLevels' => ['exception', 'error','warning'],
'emailDeliveryProfile' => 'default',
'skipEmail' => [],
'throttle' => true,
'throttleCache' => '_error_email_',
'skipThrottle' => [],
'toEmailAddress' => '[email protected]',
'fromEmailAddress' => '[email protected]',
'environment' => 'dev',
'siteName' => 'XXXXXX'
],
/**
* Configure the cache adapters.
*/
'Cache' => [
'default' => [
'className' => 'Cake\Cache\Engine\FileEngine',
'path' => CACHE,
'url' => env('CACHE_DEFAULT_URL', null),
],
'_error_email_' => [
'className' => 'File',
'prefix' => 'error_email_',
'path' => CACHE . 'error_emails/',
'duration' => '+5 minutes'
],
bootstrap.php use use ErrorEmail\Error\ErrorHandler;
Application.php use ErrorEmail\Middleware\ErrorHandlerMiddleware;
I think the plugin is well configured
I think the error can come from here:
Application.php
public function middleware($middlewareQueue)
{
$middlewareQueue
// Catch any exceptions in the lower layers,
// and make an error page/response
->add(new ErrorHandlerMiddleware(null, Configure::read('Error')))
// Handle plugin/theme assets like CakePHP normally does.
->add(new AssetMiddleware([
'cacheTime' => Configure::read('Asset.cacheTime')
]))
// Add routing middleware.
// Routes collection cache enabled by default, to disable route caching
// pass null as cacheConfig, example: `new RoutingMiddleware($this)`
// you might want to disable this cache in case your routing is extremely simple
->add(new RoutingMiddleware($this, '_cake_routes_'))
// Add csrf middleware.
/*->add(new CsrfProtectionMiddleware([
'httpOnly' => true
]))*/
;
return $middlewareQueue;
}
In this line:
->add(new ErrorHandlerMiddleware(null, Configure::read('Error')))
because when it enters in the __construct method:
ErrorHandlerMiddleware.php
public function __construct($exceptionRenderer = null, array $config = [])
{
if ($exceptionRenderer) {
$this->exceptionRenderer = $exceptionRenderer;
}
$config = $config ?: Configure::read('Error');
$this->setConfig($config);
}
$exceptionRenderer is null and read this app.php array:
'Error' => [
'errorLevel' => E_ALL,
'exceptionRenderer' => 'Cake\Error\ExceptionRenderer',
'skipLog' => [],
'log' => true,
'trace' => true,
],
but I'm not sure of all this part.
Thanks
from cakephp-error-email.
HI @pablogupi -
So I just installed a brand new fresh version of cakephp (3.8.0) and was able to get the error to be emailed assuming its coming from the cake http client with code similar to this:
$http = new Client();
$response = $http->get('http://junkhostthatdoesnotexist.test/test.html');
I just dumped that code into the default PagesController
that comes with cakephp and I got an error in my email.
I did trace the code and it is going through the ErrorEmail\Middleware\ErrorHandlerMiddleware file to handle the exception and email it.
Here is the config I used:
'ErrorEmail' => [
'email' => true,
'skipEmail' => [],
'throttle' => true,
'skipThrottle' => [],
'toEmailAddress' => '[email protected]',
'fromEmailAddress' => '[email protected]',
'environment' => 'production',
'siteName' => 'yoursite.com'
],
Your config looks correct to me and it sounds like you've correctly replaced the default error handler middleware in Application.php. Where is this exception being thrown from? A controller or somewhere else? As long as it isn't being thrown in some other existing exception/error handling code that is already past the ErrorHandlerMiddleware I don't see why it wouldn't get caught by the middleware and passed on to the email functionality.
I would try to see if you can get the exception emailed with the simplest example I listed above in a generic controller with nothing else in it and maybe work forward from there if that works.
from cakephp-error-email.
Hi!
I have found the error. In my project the multidots/public-cakephp-rest-api plugin is installed (https://github.com/multidots/public-cakephp-rest-api). This plugin contains own Middleware. Some exceptions enter in Multidots Middleware (MissingController, HttpException...) and other exception (Classnotfound, Null objects...) in your Middleware.
I'm not sure how to correct this. If change use Cake\Error\Middleware\ErrorHandlerMiddleware;
in Multidots RestApiMiddleware.php to use ErrorEmail\Middleware\ErrorHandlerMiddleware;
Emails are sent correctly in any case., but I edited file in vendor class.
I think I should create my own multidots fork but there is another simple solution. What do you think?
Thank you very much for your help
from cakephp-error-email.
Hi @pablogupi I don't see a simple obvious way to fix this. It looks like multidots prepends its middleware to the list in its bootstrapping code which also extends the error handler middleware. If its going to capture these types of exceptions before the default cakephp error handler middleware I don't think there is any way to route it into the emailing code after the fact, sorry.
These two plugins may just be incompatible. There could be something I'm missing, but I'm not seeing anything at the moment.
from cakephp-error-email.
Ok
I try to modify at the moment Multidots Middleware in vendor folder.If my tests are correct, I will create a Multidots version that uses your middleware.
Thanks for your help
from cakephp-error-email.
Related Issues (14)
- Async mails HOT 2
- Error after updating to CakePHP 3.8 HOT 6
- Ignore premature headers emission HOT 4
- EmailThrowableTrait access to context / overriding default algorithms HOT 1
- Long error message causes "File name too long" issue
- CakePHP 4.x support
- Composer HOT 3
- Image for README
- sending emails on warnings and notice error also HOT 7
- Updating preview
- Not working HOT 5
- Replace deprecated 'here' attribute HOT 1
- Replace deprecated methods setTemplate() and setLayout() HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cakephp-error-email.