eggplantSword's avatar

What is a 409 error and how can I fix it?

I get this error on two requests, one is for getting notifications and the other is for filtering data. When I get this error the whole page reloads which can be a problem since I run the get notification route every minute.

These are the methods where the error happens

public function getNotifications()
{
    $user = auth()->user();

    return back()->with('notifications', $user->unreadNotifications);
}

//this method calls to 2 other methods as well but this is the return 
public function filter(Request $request)
{
    ini_set('max_execution_time', 180);
    $filtered = $this->search($request);

    if (empty($filtered)) {
        return back()->with('info', 'No hay resultados!');
    }

    $items[] = $filtered;
    return back()->with('success', $items);
}

These are the routes

Route::get('getNotifications', 'DashController@getNotifications');
Route::post('result/filter', 'ResultController@filter');

This error only happens some times so it's not even consistent, I have no idea what it could be and how I can fix it so that it doesn't keep reloading the website.

How can I do that?

0 likes
13 replies
Sinnbeck's avatar

Just curios. Are you running inertiajs by any chance? It is known for throwing 409 (with good reason)

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

That had me confused as well. It comes from how inertia handles version. If the version changes, it forces a 403 response instead of 200. This will force the browser to make a full reload. This is handy when you update your app and the users don't refresh. That means that their frontend code is out of date (remember that you are running a single page app). Hope that makes sense

Oh and you shouldn't fix it. It works as expected

2 likes
Sinnbeck's avatar

Why would you? It is a good thing

If you want you can disable it when developing, but on production it is a must have In the service provider with your versioning, just wrap it in a production check

if (App::environment('production')) {
      Inertia::version(function () {
          return md5_file(public_path('mix-manifest.json'));
      });
}
1 like
JoeBetbeze's avatar

@Sinnbeck 3 years later with a reason: The problem I'm having is that I'm using pages and a layout. When I click to the Post page, the Layout doesn't have to remount or update. But when I click a link back to the home page, it seems the version is getting updated and forcing a 409/reload.

It's for a silly reason. I have an animation in the header that I want to keep running uninterrupted. I am seriously baffled on what to do or just if this is a silly idea to be trying.

JoeBetbeze's avatar

Ok anyone else if you're using Laravel 11, Vite, Vue3 - composition API, And Inertia with SSR AND getting 409 errors unnecessarily: The problem for me was the version of Inertia. While researching this issue you may find lots of people suggesting @inertiajs/inertia-vue3. This is because they are using an older version. You actually want the inertiajs/vue3 and more than anything you just want them to be consistent. So you'll want to npm uninstall one of the versions, and then replace all instances of it with the one you want.

Sinnbeck's avatar

Well on dev it's fine to turn off (I did so myself). But on production it is important ;)

kevindees's avatar

If you are coming from Inertia v1 and moving to v2, you will get this error if your package dependencies are using an older version and the Link from import {Link} from '@inertiajs/vue3'; will not send the x-inertia-version. Be sure all dependencies are on the same version of inertia.

Please or to participate in this conversation.