Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nnnayeem's avatar

Randomly happening Query Exception

Hello everyone,

Recently, I have faced a weird problem. I am building a SPA application. Sometimes, query exception happens for specific endpoint just by reloading.

In the handler.php


            else if($exception instanceof QueryException){
                $exception = FlattenException::create($exception);
                return response()->prettyApi([
                    'data'=>[],
                    'access'=>false,
                    'message' => config('app.env') == 'local'?$exception->getMessage():'Query Exception Occurred',
                    'status'=>400
                ]);
            }

I research and found that if I reload the page randomly generate this error because all config becomes default. For example database=forge username=forge but in the env all configuration is set properly.

This error occurs randomly if I reload the page consecutively but sometime without reloading.

It is mentionable that caching config solves this issue.

0 likes
0 replies

Please or to participate in this conversation.