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

saqueib's avatar

Add axios interceptor on nova requests

I there any way I can add interceptor for axios used in laravel nova. I have long-form I need to focus on the first error field if there is some validation error.

I already have some route beforeach hook running fine


// this is working fine
Nova.booting((Vue, router, store) => {
router.beforeEach((to, from, next) => {
    ...
    next()
})

// Add a response interceptor
axios.interceptors.response.use(function (response) {
    return response;
}, function (error) {
    // Do something with response error
    // NOT LOGING ANYTHING IN CONSOLE
    console.log(error.response)
    return Promise.reject(error);
});

I also can't handle the exception from app/Exceptions/Handler.php

public function render($request, Exception $exception)
{
    // nothing is dumped on validation error
    dd($exception);

    return parent::render($request, $exception);
}

I am using Laravel 5.8 and Nova v2.3.0, please help guys

0 likes
1 reply
saqueib's avatar

Here is how I manage to do it to focus on the input on error.

Nova.request().interceptors.response.use(function (response) {
        return response;
    }, function (error) {
        // Focus first input field with error
        let firstError = Object.keys(error.response.data.errors)[0];
        let input = document.getElementById(firstError);

        if(input) input.focus()
        
        
        return Promise.reject(error);
    });

But I think its good idea to just add it in nova itself.

I still can't handle the exception from app/Exceptions/Handler.php can someone help

Please or to participate in this conversation.