Skip to content
This repository was archived by the owner on Apr 13, 2022. It is now read-only.

Commit 1a990e9

Browse files
Use the HTTP 423 Locked status
1 parent 478487c commit 1a990e9

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
},
3737
"extra": {
3838
"branch-alias": {
39-
"dev-master": "4.3-dev"
39+
"dev-master": "5.0-dev"
4040
},
4141
"laravel": {
4242
"providers": [
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of Alt Three Locker.
7+
*
8+
* (c) Alt Three Services Limited
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
namespace AltThree\Locker\Http\Exception;
15+
16+
use Symfony\Component\HttpKernel\Exception\HttpException;
17+
use Throwable;
18+
19+
/**
20+
* This is the locked http exception class.
21+
*
22+
* @author Graham Campbell <[email protected]>
23+
*/
24+
class LockedHttpException extends HttpException
25+
{
26+
/**
27+
* Create a new locked http exception instance.
28+
*
29+
* @param string|null $message
30+
* @param \Throwable|null $previous
31+
* @param int $code
32+
* @param array $headers
33+
*
34+
* @return void
35+
*/
36+
public function __construct(string $message = null, Throwable $previous = null, int $code = 0, array $headers = [])
37+
{
38+
parent::__construct(423, $message, $previous, $headers, $code);
39+
}
40+
}

src/Http/Middleware/LockingMiddleware.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
namespace AltThree\Locker\Http\Middleware;
1515

1616
use AltThree\Locker\Exceptions\UnableToAcquireLockException;
17+
use AltThree\Locker\Http\Exception\LockedHttpException;
1718
use AltThree\Locker\Locker;
1819
use Closure;
1920
use Illuminate\Http\Request;
20-
use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException;
2121

2222
/**
2323
* This is the locking middleware class.
@@ -58,7 +58,7 @@ public function __construct(Locker $locker)
5858
* @param \Illuminate\Http\Request $request
5959
* @param \Closure $next
6060
*
61-
* @throws \Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException
61+
* @throws \AltThree\Locker\Http\Exception\LockedHttpException
6262
*
6363
* @return mixed
6464
*/
@@ -77,7 +77,7 @@ public function handle(Request $request, Closure $next)
7777
try {
7878
$response = $this->locker->execute($function, $name, 20000);
7979
} catch (UnableToAcquireLockException $e) {
80-
throw new UnprocessableEntityHttpException('Unable to acquire lock.', $e, $e->getCode());
80+
throw new LockedHttpException('Unable to acquire lock.', $e, $e->getCode());
8181
}
8282

8383
return $response;

0 commit comments

Comments
 (0)