Debug JsonAPI

39 views
Skip to first unread message

Peter Tuson

unread,
Apr 27, 2023, 5:39:48 AM4/27/23
to Joomla! General Development

I test my JsonAPI using curl within a php test script.

I have just added a new function to my API component but the test script returns with {"errors":[{"title":"Resource not found","code":404}]} even when I turn on debugging within Global Configuration. With the previous functions it works fine.

How should I go about debugging this so that I can understand why the error is occurring?

I have used grep -r to find all of the functions that define this error but not very helpful and it is not obvious whey they are being called.

Even messages are not printed.

Regards,

Peter.

Mark Stanton

unread,
Apr 27, 2023, 6:17:01 AM4/27/23
to Joomla! General Development
Personally I let the call run in debug mode in my IDE.

I use Netbeans (others are available).
I run the program in debug mode.  That starts another instance of my site, but that doesn't matter.
I then make the call.  I use a plugin to FireFox, but it should be just the same with curl.
I put breakpoints where I want/need and watch values and code to see what's going on.

This requires running a webserver on the machine I'm debugging on.  This seems to be the point at which a lot of people throw up their hands in horror, but it's really not very hard.

Peter Tuson

unread,
Apr 27, 2023, 6:53:47 AM4/27/23
to Joomla! General Development
When using the normal API in debug mode it produces  a description of the fault and a list of the functions leading to the fault - relatively easy to debug.

With the JsonAPI I get a single line. The JsonAPI is supposed to produce a JSON string for use elsewhere NOT a web browser. Hence I use curl within PHP.

So how should I really debug it without changing the web site code?

Regards,

Peter.

Mark Stanton

unread,
Apr 27, 2023, 7:17:34 AM4/27/23
to Joomla! General Development
Did you read my message at all?

It requires no change to your code whatsoever.

Peter Tuson

unread,
Apr 27, 2023, 9:25:55 AM4/27/23
to Joomla! General Development
OK, I fixed it.

On my test system, I changed the handler in the InvalidRouteExceptionHandler to print out the full error message:

    public function handle(Exception $e)
    {
        $status = 404;
        $except = print_r($e, true);
        $error  = ['title' => 'Invalid Route: Resource not found'];
        $error['except'] = $except;

This then included a description of the actual error and a trace to it. This then allowed me to work out how to fix it, which was to include the new function in the webservices plugin.

It would be useful if this error detail and trace were automatically produced when debugging is turned on.

Also there are two Resource not found errors and these should have different titles as I have shown in the above text.

Regards,

Peter.

Tomas Dalebjörk

unread,
May 22, 2023, 7:06:59 PM5/22/23
to Joomla! General Development
I embeded the smtp mailer in the code, just to debug it, as I also run into this issue.
And than read the email to understand what's going on.

That helped me
Reply all
Reply to author
Forward
0 new messages