Skip to content

Commit 7a4a27b

Browse files
authored
Merge pull request #48 from yormy/throw_exception_on_blocked
thow exception when middleware blocks the request
2 parents 258be5f + f8a0b3e commit 7a4a27b

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

src/Abstracts/Middleware.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ public function respond($response, $data = [])
160160
abort($response['code'], trans('firewall::responses.block.message'));
161161
}
162162

163+
if (array_key_exists('exception', $response)) {
164+
if ($exception = $response['exception']) {
165+
throw new $exception();
166+
}
167+
}
168+
163169
return Response::make(trans('firewall::responses.block.message'), $response['code']);
164170
}
165171
}

src/Config/firewall.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
'redirect' => env('FIREWALL_BLOCK_REDIRECT', null),
2020
'abort' => env('FIREWALL_BLOCK_ABORT', false),
2121
'code' => env('FIREWALL_BLOCK_CODE', 403),
22+
'exception' => \Akaunting\Firewall\Exceptions\FirewallBlockedException::class,
2223
],
2324

2425
],
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Akaunting\Firewall\Exceptions;
4+
5+
use Exception;
6+
7+
class FirewallBlockedException extends Exception
8+
{
9+
// Empty implementation as a stub for your own exception
10+
}

0 commit comments

Comments
 (0)