Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

227
Views
Why block .catch(error => { is not run on not found error in axios request?

In laravel 9 app with axios 0.25 when making request to server

axios.post(route('frontend.get_block_cms_item'), filters)
    .then(({data}) => {
        main_page_contact_us_title.value = data.cMSItem.title
        main_page_contact_us_text.value = data.cMSItem.text
    })
    .catch(error => {
        console.error(error)
    })

I use code when item is not found :

    public function get_block_cms_item(Request $request)
    {
        $key     = $request->key;
        $cMSItem = CMSItem
            ::getByKey($key)
            ->getByPublished(true)
            ->first();
        if (empty($cMSItem)) {
            return response()->json([
                'message' => 'CMS Item with key "' . $key . '" not found !',
                404
            ]);
        }

but code .then(({data}) => is called and I got run time error :

typeError: Cannot read properties of undefined (reading 'title')

I expected that

.catch(error => {

must be run and I will not get error...

How that can be fixed ?

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!