Skip to content

Latest commit

 

History

History
45 lines (28 loc) · 1.58 KB

File metadata and controls

45 lines (28 loc) · 1.58 KB

Error Handling

Notifications uses package exceptions for invalid state, missing channels, unsupported delivery, driver failures, and failed delivery results.

Creation Errors

InvalidNotificationException is thrown when notification or recipient payloads are not valid:

  • notification content is empty;
  • recipient address is empty;
  • metadata, data, or detail keys are invalid;
  • recipient payload shape is not recognized;
  • a channel-specific send has no eligible recipients.

Channel Errors

InvalidNotificationChannelException is thrown for malformed channel names.

ChannelNotFoundException is thrown when a requested channel is not registered.

ChannelAlreadyRegisteredException is thrown by registerChannel() or ChannelRegistry::register() when a channel already exists.

Driver Errors

UnsupportedNotificationException is thrown when a driver returns false from supports().

Unexpected driver throwables are wrapped in NotificationDriverException. Notification exceptions thrown by a driver are allowed to bubble out unchanged.

Drivers should return DeliveryResult::failed() when a provider safely processed the request and returned a failure status. Drivers should throw an exception when delivery could not be attempted safely.

Failed Results

Failed results are not thrown automatically. Call throwIfFailed() when the caller wants exception flow:

$result = $notifier->send($notification, 'email');
$result->throwIfFailed();

For multi-channel sends:

$report = $notifier->sendToChannels($notification, ['email', 'sms']);
$report->throwIfFailed();