Not well JSON formatted response

I just bought the Enterprise edition of the library and installed it (Grocery CRUD Enterprise v3.2.2) in a new CodeIgniter 4 project, I followed the steps in the documentation but I got this error.
This is the error and my code

I hope you can help me

Hello @juanjovill21 and welcome to our forums :slight_smile:

It seems that the issue is with the routes. Most probably you haven’t added post requests. A simple rule for the routes can be to do something like this:

$routes->add('/example/customers', 'Example::customers');
$routes->add('/example/customers/(:segment)(/(:segment))?', 'Example::customers/$1/$2');

At the file app/Config/Routes.php , let me know if that worked for you.

Regards
Johnny

I already added both lines, It was different in my version, but it doesn’t works, stills the same error.

Message: We can’t process the response of the server. Not well JSON formatted response.

Hello @juanjovill21 ,

After spending a bit of time, I guess the problem is that you are getting an exception but it is not visible, so from your code if you change the exception line to something like this:

    } catch (\Exception $e) {
            // Directly return the string
             return '<div class="alert alert-danger"><h4>Error en Grocery CRUD</h4><p><strong>Error:</strong> '
                . $e->getMessage() . '</p><p><strong>Archivo:</strong> ' . $e->getFile()
                . '</p><p><strong>Línea:</strong> ' . $e->getLine() . '</p></div>';
    }

By returning only the error, this should show you the error that you are having.

Let me know if that helped you debug your issue. Once this is fixed we can have a more user friendly message for the end user.

I deleted the try and catch from my code, but now I got another error
image

Hello @juanjovill21 ,

That means that the error is unhandled and you have most probably disabled the error reporting (and that’s why you see blank screen)

Have you tried the try catch but with just returning the error from the previous message? Did that work? From my experience this is usually when there is a database connection that doesn’t work. What database are you using? Is that mySQL or Postgres? Also I have sent you an email, so I would suggest if you can share me a bit more of your code through email. For example your controller so I can understand further and resolve it faster with also faster responses.

The email address is: info@grocerycrud.com

Regards
Johnny