How to hide generic datatable editor error
How to hide generic datatable editor error
Benoit87
Posts: 10Questions: 4Answers: 1
Hello,
I would like to hide generic datatable editor error like "System Error" or "SQL Error".
I begin to do below but now all my custom error like "Nothing data." are replaced by "An error occured. Contact IT support."
It's possible to keep custom error and handle generic datatable error only to "An error occured. Contact IT support."
Thanks You
$editor = Editor::inst( $db, 'PERSONEL', 'PERSONELTABLE' )
->fields(
Field::inst( 'USERID' )->validator( 'Validate::notEmpty' )
)
->validator(function ($editor, $action, $data){
if ($action === Editor::ACTION_EDIT || $action === Editor::ACTION_DELETE){
if(count($data["data"]) === Null){
return "Nothing data.";
}
if(count($data["data"]) > 0){
return "Can't modify multiple row.";
}
}
})
->process( $_POST );
// Vérification de la présence d'une erreur dans le retour JSON
$response = $editor->data();
// Si une erreur est détectée, modifier le message d'erreur
if (isset($response['error'])) {
$response['error'] = "An error occured. Contact IT support.";
}
// Retourner la réponse JSON
echo json_encode($response);
Answers
I'd strongly suggest not hiding the error, but rather fixing the issue .
The generic error will appear if there is invalid JSON returned from the server. Possibly the server is returning a PHP warning? If so, that needs to be corrected.
If you want to change the value of the default error message, use
i18n.error.system
.Allan
Hi, yes iam agree with you but sometimes it could have mistakes or connection issue ... My code sample is ok but i don't want to give too much details if an unknown error appears.
And i prefer server-side if its possible.
Yes, in the case of a generic failure such as a connection issue, the client-side error string will be shown. That is what can be configured with
i18n.error.system
.Allan