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

238
Views
¿Por qué bloquear .catch(error => { no se ejecuta en un error no encontrado en la solicitud de axios?

En la aplicación laravel 9 con axios 0.25 al realizar una solicitud al servidor

 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) })

Uso el código cuando no se encuentra el artículo:

 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 ]); }

pero se llama al código .then(({data}) => y obtuve un error de tiempo de ejecución:

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

Yo esperaba que

 .catch(error => {

debe ejecutarse y no me dará error...

¿Cómo se puede arreglar eso?

¡Gracias por adelantado!

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!