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!