Skip to content

Commit 6f894af

Browse files
committed
feat: Throw exception when template id don't exist on Brevo
1 parent ff91588 commit 6f894af

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed

src/BrevoEmailChannel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Database\Eloquent\Model;
88
use Illuminate\Notifications\AnonymousNotifiable;
99
use Illuminate\Notifications\Notification;
10+
use YieldStudio\LaravelBrevoNotifier\Exceptions\BrevoException;
1011

1112
class BrevoEmailChannel
1213
{

src/BrevoService.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use Illuminate\Http\Client\PendingRequest;
88
use Illuminate\Support\Facades\Http;
9+
use YieldStudio\LaravelBrevoNotifier\Exceptions\BrevoException;
910

1011
class BrevoService
1112
{
@@ -45,6 +46,13 @@ public function sendEmail(BrevoEmailMessage $email, array $options = []): ?array
4546
} elseif (array_key_exists('emailFrom', $options)) {
4647
$email->from($options['emailFrom']);
4748
}
49+
50+
$templateResponse = $this->http->get('/smtp/templates/'. $email->templateId);
51+
52+
if (! $templateResponse->successful()) {
53+
throw new BrevoException($templateResponse->toPsrResponse());
54+
}
55+
4856
$response = $this->http->post('/smtp/email', $email->toArray());
4957

5058
if (! $response->successful()) {

src/BrevoSmsChannel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Database\Eloquent\Model;
88
use Illuminate\Notifications\AnonymousNotifiable;
99
use Illuminate\Notifications\Notification;
10+
use YieldStudio\LaravelBrevoNotifier\Exceptions\BrevoException;
1011

1112
class BrevoSmsChannel
1213
{

src/BrevoException.php renamed to src/Exceptions/BrevoException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace YieldStudio\LaravelBrevoNotifier;
5+
namespace YieldStudio\LaravelBrevoNotifier\Exceptions;
66

77
use Exception;
88
use Psr\Http\Message\ResponseInterface;

0 commit comments

Comments
 (0)