-
-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature | Debug Helper Method #387
Conversation
Just replying here instead of twitter. So what I mean by my suggestion was to update the HasDebugging Trait to have two new functions: trait HasDebugging
{
public function dump()
{
return debug($this);
}
public function dd()
{
return debug($this, true);
}
............ So instead of importing it when used, we could do: $connector->send($request->dump()); Side note in terms of the code itself. I think laravel Octane has a problem with |
I actually really love that idea. We already have the |
I think as long as its documented it'll be fine. People always reach for the docs when trying to debug things like this anyway This however might make it easy enough to remember for next time instead of having to look it up again (like I always do) |
I've added it to the trait, is that what you were thinking? I'm still considering it - I might remove it if I feel it could clash too much with Laravel |
Having both would be perfect and would have saved me a lot of time in the past. Might be counter intuitive having it on the request instead of the connection but thats minor in comparison to the benefit you get here |
Okay so I've made some more changes - now we have on the connector/request the following: $connector->debug($die = false); // Outputs request and response
$connector->debugRequest(); // Outputs request (no die)
$connector->debugRequest($closureHandler); // Old functionality
$connector->debugResponse(); // Outputs response (no die)
$connector->debugResponse($closureHandler); // Old functionality Not even sure if we need the |
That looks neat and very usable. Likely easy to remember too |
Thank you for the help with this! |
If you debug the connector, include as much as possible for the lifecycle. If you debug the request, it’s typically because I want to see what is being sent, though I can see a scenario where seeing the response (that would otherwise end up triggering the exception handling), would be helpful |
Hey @ClaraLeigh @michaeldyrynda I have updated the description at the top with the final changes. I have also removed the |
Hi @Sammyjo20! Thanks for simplifying debugging! And what about "entering a debug mode" as using cache or not? For me PS. Will the old way of debugging be still active? To keep it backwards compatible? |
Hey @Sammyjo20! I'm loving the newer version of the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Self review
Hey @boryn thank you for taking a look at this although I don't think I can get it too much simpler than public function __construct()
{
$this->debug();
} Yes the previous functionality will remain 🙌 |
These changes saved me a lot of time this week doing two new api integrations. Very helpful and easy to remember, ty |
Woohoo! That’s great 😀 thank you for letting me know! |
(Updated description)
This PR introduces a new and exciting way to debug Saloon requests! We previously had the
debugRequest
anddebugResponse
methods on the connector/request however they required you to define your own callback to debug with, which was cumbersome.Let's take a look at an example of dumping out the PSR request's raw request body:
That's a lot of code just for debugging! This PR now makes the callable argument nullable and provides a nice default implementation to quickly debug requests and responses. This is all you have to write now:
Much cleaner! It will output the raw request in an array format using Symfony's Var Dumper library.
Responses
But wait, there's more! I have also provided a default implementation for debugging responses. This works in exactly the same way:
Combined
Most of the time you want to write an even shorter method and get both the request and response at the same time. You can now use a new
debug()
method.Note
All of these are available on the request instance too.
Dump & Die
When debugging a common practice is to exit the application after dumping out the useful information. All of the methods now have a "die" argument which can be provided to exit the application.
Todo