0
votes

i'm using laravel and vue, i use axios to make a request, that request response a json, but if cannot find the data, return a 404,but catch of axios don't work

this is the front code

methods:  {
            updateData: function () {
                axios.post('acd/' + this.number + '/' + this.date)
                .then((response) => {
                    this.setData(response['data'])
                }).catch(err => {
                    console.log("this dont display")
                });
                setTimeout(this.updateData, 1000)
                this.updateDoughnutChart();
                this.updateLineChart();
                this.updatePieChart();
            },

and this is the back code

public function getAcd(Request $request, $id, $date)
    {
        $dateClient = new Carbon($date);
        $dateServer = new Carbon;
        
        if($dateClient->format('Y-m-d') == $dateServer->format('Y-m-d'))
        {
            $data = App::make('vodia')->getAcd($id);
        }
        else
        {
            $data = Call::where('acd', $id)->whereDate('created_at', $date)->firstOrFail();
            $data = json_decode($data->data);
        }
        

        return response()->json(($data));
    }

this is the console error

Uncaught (in promise) Error: Request failed with status code 404
1

1 Answers

0
votes

Think the syntax for the catch block is not correct

your code

axios.post('acd/' + this.number + '/' + this.date)
                .then((response) => {
                    this.setData(response['data'])
                }).catch(err => {
                    console.log("this dont display")
                });

suppose to be

axios.post('acd/' + this.number + '/' + this.date)
                .then((response) => {
                    this.setData(response['data'])
                }).catch((err) => {
                    console.log(err)
                });