I want to catch any error (ie: foreign key error) from an insert
statement or any other. How can I achive that with use Doctrine\DBAL\Exception
?
I have this when I do the insert
:
$db->beginTransaction();
try {
$db->insert('bbc5.produccionpry',$datos);
$datos['propryid'] = $db->lastInsertId();
$db->commit();
// $db = null;
$resp[] = $datos;
} catch (Exception $e) {
$error = array_merge($error, array('error' => $e->errorInfo()));
$db->rollback();
throw $e;
}
But, that doesn't prevent the concrete5 to return
a website telling about the error, so, I don't want that website to be shown, I want to catch the error in an array()
in order to return it via echo json_encode($error)
I'm not using the controller for a page, I'm using it for managing RESTful calls from my JavaScript App with this code:
return fetch(`/scamp/index.php/batchprodpry/${maq}`, {
method: 'POST',
credentials: 'same-origin',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(this.state.a)
})
I'm using ReactJS
Thank you