Skip to content

Commit c321ce3

Browse files
authored
Merge pull request #3 from middlewares/feature/use-utils-error-exception
Use HTTP error exception from utils
2 parents 08afe22 + 826b292 commit c321ce3

File tree

3 files changed

+10
-92
lines changed

3 files changed

+10
-92
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## [1.1.0] - ???
9+
10+
### Changed
11+
12+
- Use `HttpErrorException` from utils package
13+
814
## [1.0.0] - 2018-01-26
915

1016
### Added

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
"require": {
1818
"php": "^7.0",
19-
"middlewares/utils": "^1.0",
19+
"middlewares/utils": "^1.1",
2020
"psr/http-server-middleware": "^1.0"
2121
},
2222
"require-dev": {

src/HttpErrorException.php

Lines changed: 3 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,10 @@
11
<?php
2-
declare(strict_types = 1);
2+
declare(strict_types=1);
33

44
namespace Middlewares;
55

6-
use Exception;
7-
use RuntimeException;
8-
use Throwable;
6+
use Middlewares\Utils\HttpErrorException as BaseException;
97

10-
class HttpErrorException extends Exception
8+
class HttpErrorException extends BaseException
119
{
12-
private static $phrases = [
13-
// CLIENT ERROR
14-
400 => 'Bad Request',
15-
401 => 'Unauthorized',
16-
402 => 'Payment Required',
17-
403 => 'Forbidden',
18-
404 => 'Not Found',
19-
405 => 'Method Not Allowed',
20-
406 => 'Not Acceptable',
21-
407 => 'Proxy Authentication Required',
22-
408 => 'Request Time-out',
23-
409 => 'Conflict',
24-
410 => 'Gone',
25-
411 => 'Length Required',
26-
412 => 'Precondition Failed',
27-
413 => 'Request Entity Too Large',
28-
414 => 'Request-URI Too Large',
29-
415 => 'Unsupported Media Type',
30-
416 => 'Requested range not satisfiable',
31-
417 => 'Expectation Failed',
32-
418 => 'I\'m a teapot',
33-
421 => 'Misdirected Request',
34-
422 => 'Unprocessable Entity',
35-
423 => 'Locked',
36-
424 => 'Failed Dependency',
37-
425 => 'Unordered Collection',
38-
426 => 'Upgrade Required',
39-
428 => 'Precondition Required',
40-
429 => 'Too Many Requests',
41-
431 => 'Request Header Fields Too Large',
42-
444 => 'Connection Closed Without Response',
43-
451 => 'Unavailable For Legal Reasons',
44-
// SERVER ERROR
45-
499 => 'Client Closed Request',
46-
500 => 'Internal Server Error',
47-
501 => 'Not Implemented',
48-
502 => 'Bad Gateway',
49-
503 => 'Service Unavailable',
50-
504 => 'Gateway Time-out',
51-
505 => 'HTTP Version not supported',
52-
506 => 'Variant Also Negotiates',
53-
507 => 'Insufficient Storage',
54-
508 => 'Loop Detected',
55-
510 => 'Not Extended',
56-
511 => 'Network Authentication Required',
57-
599 => 'Network Connect Timeout Error',
58-
];
59-
60-
private $context = [];
61-
62-
/**
63-
* Create and returns a new instance
64-
*
65-
* @param int $code A valid http error code
66-
* @param array $context
67-
* @param Throwable|null $previous
68-
*
69-
* @return static
70-
*/
71-
public static function create(int $code = 500, array $context = [], Throwable $previous = null): self
72-
{
73-
if (!isset(self::$phrases[$code])) {
74-
throw new RuntimeException("Http error not valid ({$code})");
75-
}
76-
77-
$exception = new static(self::$phrases[$code], $code, $previous);
78-
$exception->setContext($context);
79-
80-
return $exception;
81-
}
82-
83-
/**
84-
* Add data context used in the error handler
85-
*/
86-
public function setContext(array $context)
87-
{
88-
$this->context = $context;
89-
}
90-
91-
/**
92-
* Return the data context
93-
*/
94-
public function getContext(): array
95-
{
96-
return $this->context;
97-
}
9810
}

0 commit comments

Comments
 (0)