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!