Chapters
29 Chapters
|
1:34:37
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!Compatible PHP versions: >=5.3.3
Subscribe to download the code!Compatible PHP versions: >=5.3.3
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
18.
Customizing Error Pages and How Errors are Handled
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=5.3.3",
"symfony/symfony": "~2.4", // v2.4.2
"doctrine/orm": "~2.2,>=2.2.3", // v2.4.2
"doctrine/doctrine-bundle": "~1.2", // v1.2.0
"twig/extensions": "~1.0", // v1.0.1
"symfony/assetic-bundle": "~2.3", // v2.3.0
"symfony/swiftmailer-bundle": "~2.3", // v2.3.5
"symfony/monolog-bundle": "~2.4", // v2.5.0
"sensio/distribution-bundle": "~2.3", // v2.3.4
"sensio/framework-extra-bundle": "~3.0", // v3.0.0
"sensio/generator-bundle": "~2.3", // v2.3.4
"incenteev/composer-parameter-handler": "~2.0", // v2.1.0
"doctrine/doctrine-fixtures-bundle": "~2.2.0", // v2.2.0
"ircmaxell/password-compat": "~1.0.3", // 1.0.3
"phpunit/phpunit": "~4.1", // 4.1.0
"stof/doctrine-extensions-bundle": "~1.1.0" // v1.1.0
}
}
11 Comments
Hey there, I'm liking a lot this episode.
I has a problem when loading CSS and Images in Prod enviroment. (When I try to browse to "localhost:8000/app.php" )
I got error 404 Not Found.
Clearing cache didn't fix it and then I found this command
# php app/console assetic:dump --env=prod
It did the trick
I hope somebody else find it helpful
Cheers!
Diego! You're totally right - we're using Assetic, but we don't really talk about it until episode 4: https://knpuniversity.com/s...
Thanks for adding the note :)
No problem ;]
I like to help
This topic requires a full course.
I still dont know what is actually the best way to handle errors or how to work with them from developers point of view.
Does the developer suppose to check log file on production like every day, hour, minutes?
Imagine customer will see error 400 and will send me an email: something is not working... when I wanted to see elephant.
I will probably go to prod.log and see all errors within last few days as he didnt specified time and where exactly he couldnt see elephant.
What I would like to do is on any error. System, permission, 404, 500 json etc saved Error(Exception) in database and show a unique number to customer as reference which he can email to me or automatically I will get an email with that reference.
something like below: "Hi John Snow, something went wrong status code status text we are dealing with your error Err1234321. Sorry for any inconvenience. Email has been sent to us and we are working hard to fix it. We will inform you once its done."
Then I would go to database and see basically exactly the same info like being on dev but have these information in database instead of .log file and storing also username if user was logged.
I believe this would be more beneficial for coders as well as I would be able to filter errors for that user for given time frame and if user would send me a reference number I would see exactly the error number and fix it.
I am reading about ErrorController and how to overwrite but didnt find any real life code or good explanation.
In other words I am looking for Log -> Level Error -> Error Message to be stored in DB with User and sending automatic email to me.
Hey Peter,
I'd add this topic to our possible screencasts list, but unfortunately I can't say when this course might be released.
A few words about it: you probably don't want to get notifications for 4xx errors on production. Because those errors might be too much, and it will just spam you a lot. Basically, 4xx are client errors that means it's client fault to generate them. Like, client is trying to open a page that does not exist, or client just does not have access to the resource, etc. Usually, you want to track only 5xx errors on production, that means something is wrong on server side.
About getting notifications when something is wrong - sure, that would be useful! But it depends on *you*. There's a lot of way to do it: you can get those notifications via Slack, or to your Telegram/Viber channel, or get them by emails, though it's not popular lately thanks to Slack and messengers :) Actually, you even may want to receive notifications not only problems, but also about something important that happened in your application, e.g. you got a new customer that paid you 10 000$ :) And Symfony has a component that would help with it. Check Fabien's talk about Symfony Notifier Component: https://symfonycasts.com/sc... - or read docs about it here: https://symfony.com/doc/cur... . Unfortunately, we don't have a course about it, but we would like to release one some day. Actually, Monolog bundle also may send different alerts, see: https://github.com/Seldaek/...
Except this, there's a lot of interesting built-in handlers in MonologBundle, that may collect logs, handles them and warn your about something bad happen in your application. For example, see Sentry, Rollbar, NewRelic, Loggly handlers: https://github.com/Seldaek/... . And yes, Monolog may log into the DB though I've never done this, see: https://github.com/Seldaek/...
So, yes, you can easily override Symfony error pages, like 4xx / 5xx pages and say something like "We're sorry for this error. We created a ticket ### and our team is already working on it. If you have any questions about it - please, email us and specify this ticket number" something like this. To actually save that information I believe you can use Symfony events and check status of the response. If it's a bad response status - save info to the DB with all the useful into like current user, logs, etc.
There might be some bundle that already may do this job completely or partially, but I don't know any unfortunately.. Try to google it or use GitHub search. Anyway, even if there's no any ready-to-use solution - you are able to write this system yourself for your project.
I hope this helps!
Cheers!
I end up with using monolog.
It is not perfect at all.
I managed to email and log them into files but Ive noticed URL is not passed.
Different behavior on dev and prod not sure how to set it up.
Not sending user id who has generated this error (if known)
Example is I tried to access undefined variable on dev it will trow 500 exception but on prod it is ignoring this error.
Also not sure how to create unique reference on template.
Not sure how to access for 403 pages with @isGranted permission option for roles like Admin, Superadmin how to display it on 403 error page.
Error would look like "Sorry you need Admin or Superadmin permission to access this page."
I was reading about overriding ErrorController but not sure what else I would break so rather keeping it as it is.
That is just storing errors into file and/or emailing but what about storing errors in DB, I have no idea....
Too many possibilities and documentation is confusing so I would really appreciate a good tutorial with real life example if someone has any
Hey Peter,
Symfony logs some simple default things our of the box... but of course you can easily add your logs :) You can log whatever you want, including the current user. Just use Symfony event for this and add logging of whatever info you think might be useful for you for debugging.
Cheers!
Hello Ryan!
Hope you are doing good!
In this chapter I've had an issue while I was triying to clear out the cache in order to run the application to the prod enviroment.
Here what I got:
$ ./app/console cache:clear --env=prod
[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]
The parameter "stof_doctrine_extensions.uploadable.validate_writable_direct
ory" must be defined.
As you can see I can't access to the production enviroment because of this if I put an "/app.php"
Thanks in advance for your time and help!
Edison
Hi Edison!
Hmm, so I've looked at the StofDoctrineExtensionsBundle library, and I'm not sure how this is happening. This parameter should be set for you, even if you do nothing. But, based on what that library is doing, it may just be a one-time issue that you can fix by manually clearing the cache this one time:
Try that, then try the cache:clear command again. I bet this will do it.
Ah, in fact I just found the issue - and the above work-around is "correct": https://github.com/stof/StofDoctrineExtensionsBundle/issues/205
So, not your fault. Fix it and keep going :).
Cheers!
Hello Again Ryan!
I finally made it on the Error Pages, Thank You! (cache file, it solves the issue)
Now I'm in Epsidoe 4. I installed nodejs binary.exe for OS Windows8 64x, (choosed npm manager package) but it is not working...-bash npm not found...I am using masteruser.
What else should I do....? Thx!!!!!!!!!!!!!!!!!
Hey Edison!
Yes, path issues are always a pain in the butt! Here are a few suggestions:
1) If you're not already, try using a bash other than cmd - like the "git bash" that comes when you install git. This *may* help with your paths, but there's a good chance it won't.
2) With npm, you can install things globally (npm install -g foo) or locally (npm install foo), which installs things into a node_modules directory right in your project. With the global install, your terminal path needs to be setup correctly to know what directory to look in for stuff. But if you instal locally, then you should have a binary located in something like node_modules/.bin/nodejs. Then, you can update your config.yml to point to this path (look at line 9 in the first code-bock here: http://symfony.com/doc/curr....
Let me know if this gets you closer!
Cheers!
"Houston: no signs of life"
Start the conversation!