Skip to content
This repository has been archived by the owner on Sep 27, 2019. It is now read-only.

emit NotificationFailed on critical failure #4

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/IntercomChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Intercom\IntercomClient;
use Illuminate\Notifications\Notification;
use GuzzleHttp\Exception\BadResponseException;
use Illuminate\Notifications\Events\NotificationFailed;
use FtwSoft\NotificationChannels\Intercom\Exceptions\RequestException;
use FtwSoft\NotificationChannels\Intercom\Contracts\IntercomNotification;
use FtwSoft\NotificationChannels\Intercom\Exceptions\InvalidArgumentException;
Expand Down Expand Up @@ -76,6 +77,12 @@ public function send($notifiable, Notification $notification): void
$message->toArray()
);
} catch (BadResponseException $exception) {
event(new NotificationFailed($notifiable, $notification, $this, [
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't have to do like that. This is unattended behavior, also event is not obvious dependency, there is EventDispatcher class exists for that
You must catch this Exception on your business layer

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you point me the proper way to catch that? In my testing, once the Notification has been given over to Laravel there's no way to catch errors it throws

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to read manual and internal Laravel code more accurately.
Unfortunately, I can't help you with this now

'message' => $message,
'error' => $exception->getMessage(),
])
);

throw new RequestException($exception, $exception->getMessage(), $exception->getCode());
}
}
Expand Down
171 changes: 170 additions & 1 deletion tests/Mocks/TestFakeApplication.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace FtwSoft\NotificationChannels\Intercom\Tests\Mocks;

use Closure;
use Illuminate\Container\Container;
use Illuminate\Contracts\Foundation\Application as ApplicationContract;

Expand All @@ -24,7 +25,7 @@ public function basePath()
/**
* {@inheritdoc}
*/
public function environment()
public function environment(...$environments)
{
}

Expand Down Expand Up @@ -104,4 +105,172 @@ public function getCachedServicesPath()
public function getCachedPackagesPath()
{
}

/**
* {@inheritdoc}
*/
public function bootstrapPath($path = '')
{
}

/**
* {@inheritdoc}
*/
public function configPath($path = '')
{
}

/**
* {@inheritdoc}
*/
public function databasePath($path = '')
{
}

/**
* {@inheritdoc}
*/
public function environmentPath()
{
}

/**
* {@inheritdoc}
*/
public function resourcePath($path = '')
{
}

/**
* {@inheritdoc}
*/
public function storagePath()
{
}

/**
* {@inheritdoc}
*/
public function resolveProvider($provider)
{
}

/**
* {@inheritdoc}
*/
public function bootstrapWith(array $bootstrappers)
{
}

/**
* {@inheritdoc}
*/
public function configurationIsCached()
{
}

/**
* {@inheritdoc}
*/
public function detectEnvironment(Closure $callback)
{
}

/**
* {@inheritdoc}
*/
public function environmentFile()
{
}

/**
* {@inheritdoc}
*/
public function environmentFilePath()
{
}

/**
* {@inheritdoc}
*/
public function getCachedConfigPath()
{
}

/**
* {@inheritdoc}
*/
public function getCachedRoutesPath()
{
}

/**
* {@inheritdoc}
*/
public function getLocale()
{
}

/**
* {@inheritdoc}
*/
public function getNamespace()
{
}

/**
* {@inheritdoc}
*/
public function getProviders($provider)
{
}

/**
* {@inheritdoc}
*/
public function hasBeenBootstrapped()
{
}

/**
* {@inheritdoc}
*/
public function loadDeferredProviders()
{
}

/**
* {@inheritdoc}
*/
public function loadEnvironmentFrom($file)
{
}

/**
* {@inheritdoc}
*/
public function routesAreCached()
{
}

/**
* {@inheritdoc}
*/
public function setLocale($locale)
{
}

/**
* {@inheritdoc}
*/
public function shouldSkipMiddleware()
{
}

/**
* {@inheritdoc}
*/
public function terminate()
{
}
}