14.
Debugging and Cleanup
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.
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
Whoops, an error! Please, try again later.
12 Comments
Hi, in sf 4.4 i didn'd add api_exception_subscriber with it's argument and api.response_factory from rest4 and all working good, does they work by autowiring or am ruining how symfony services should work?
Hey Mouad,
Yes, it should work in 4.4. with thanks to the interface the subscriber implements. To be 100% sure it works - you can put a "die" statement somewhere in ApiExtensionSubscriber, e.g. in onKernelException and try to trigger that code. If you hit your "die" statement - then it 100% work :)
Cheers!
Thanks a lot! great one. I am anxiously waiting for the next episodes. Cheers!
Might only be me but I see an issue. In production, if you get an internal error 500, it will send a nice json response. But if you don't put a logger in there, yes the error is raised but never logged server side. So you're blind if there are issues in production
Actually, I think you're 100% correct about that. Exceptions are normally logged by Symfony, but this happens in the default ExceptionListener. By setting the response in *our* listener, we stop propagation and that other listener is never called (so the exception is never logged). You *should* log the exception inside of here :). I'll add a note about that!
Thanks for pointing this out!
Hi,
I run symfony 3 and I have a AutowiringFailedException syaing that $debug is missing type-hint or have a given a value explicitly
What can I do?
Yo julien moulis!
If you're going to use Symfony 3.3 with the new service configuration stuff, then you'll need to change a few things. The most important one is that you'll need to use class names as the service ids. Let me explain (and I believe this is the solution to your problem). The tutorial has this:
But if you're using the Symfony 3.3 config, then there is a section above this (the section with
resource) which auto-registers all services in your src/ directory. When it does this, the service ids use the class name. So, if you keep the above code, you're actually registering a second service with the container. This second service is configured correctly. But the first service (the one that's auto-registered) is missing its first argument ($debug).So, change to use the class name as the service id:
When you do this, you're overriding the auto-registered service and configuring it further. Now, we have just one service, and we ARE passing in the missing first argument. But actually, you can do even less work. You only need this:
Thanks to autowiring, all the other arguments of the constructor will still be autowired automatically. And thanks to autoconfigure, you actually don't need to specify the tag - it's added automatically.
I don't know if you've gone through it yet, but check out our Symfony 3.3 tutorial (https://knpuniversity.com/screencast/symfony-3.3) if you're interested in this stuff. There is an optional paradigm shift happening in Symfony right now that will feel a bit disruptive. But, the end result is awesome: you're going to working faster and writing more of your code, instead of going back to configuration files constantly.
Cheers!
This no longer appear to work (Symfony 4)?
I have put:
Yet still get this error:
Hey Doug Hayward
Sorry for the late response! Do you still have this problem?
BTW, it should work, maybe you just have to clear the cache. If that's not the case, lets us know :)
Cheers!
I cured the error by setting the value default value in the constructor, I'm sure this is an incorrect way of fixing it but it worked for the time being:
Yes I cleared my cache no it didn't fix it.
Wow, that's strange. I'm going to investigate why this is happening, but if in the meantime you find the answer, please, let us know :)
Have a nice day
Thank you so much!!!!!
"Houston: no signs of life"
Start the conversation!