Fix the error shown when trying to create a Customer with no linked Mailbox

This commit is contained in:
Antoine Le Gonidec 2024-07-22 18:35:47 +02:00
parent d61183c0a8
commit 732695922a
Signed by: vv221
GPG key ID: 636B78F91CEB80D8

View file

@ -70,7 +70,13 @@ class MMFRestrictedCustomersServiceProvider extends ServiceProvider {
if ( array_key_exists('mailbox_id', $data) ) {
$customer->mailbox_id = $data['mailbox_id'];
} else {
$customer = Customer::find($customer->id);
$customer_id = $customer->id;
if ( $customer_id == null ) {
Log::error('The creation of a Customer with no link to a Mailbox is not allowed, and has been aborted.');
// TODO: Error out more gracefully.
abort(500, 'The creation of a Customer with no link to a Mailbox is not allowed, and has been aborted.');
}
$customer = Customer::find($customer_id);
if ( $customer == null ) {
Log::error('Trying to use a Customer in another Mailbox than the one it is linked to is not allowed, and has been aborted.');
// TODO: Error out more gracefully.