PluginProbe
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses / 2.8.1
FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses v2.8.1
2.11.0 2.10.0 2.10.01 2.9.1 2.9.0 2.8.1 2.8.0 2.7.7 2.7.5 2.7.0 2.6.01 2.6.0 2.5.0 2.4.01 trunk 1.0.90 1.0.91 1.0.92 1.0.93 1.0.94 1.0.95 1.0.96 1.0.97 1.0.98 1.0.99 All 78 releases
fluent-community / vendor / wpfluent / framework / src / WPFluent / Foundation / Exceptions / HttpException.php

HttpException.php in FluentCommunity – Ultra-Fast High-Performance Social Network, Community, LMS & Online Courses 2.8.1, at vendor/wpfluent/framework/src/WPFluent/Foundation/Exceptions/HttpException.php

114 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCommunity\Framework\Foundation\Exceptions;
4
5 use Exception;
6 use Throwable;
7
8 /**
9 * Base class for exceptions that represent an intentional, user-safe
10 * HTTP response. Carries an HTTP status code, a machine-readable error
11 * code, optional structured data, and optional response headers.
12 *
13 * Subclasses pin the status code (NotFoundHttpException = 404, etc.) so
14 * call sites read as `throw new ForbiddenHttpException($why)` — the
15 * status is implicit in the type.
16 *
17 * Route::callback() catches HttpException before its handleUnknownException
18 * sanitizer, so the message and status reach the client verbatim. This is
19 * the opt-in escape hatch from the production message sanitization that
20 * protects against leaking PDO / file-system / transport internals.
21 */
22 class HttpException extends Exception
23 {
24 /**
25 * HTTP status code to report.
26 *
27 * @var int
28 */
29 protected $statusCode;
30
31 /**
32 * Machine-readable error code, stable across versions
33 * (e.g. 'widgeteer_token_rejected') for frontend branching.
34 *
35 * @var string
36 */
37 protected $errorCode;
38
39 /**
40 * Optional structured data emitted in the response body.
41 *
42 * @var array
43 */
44 protected $data;
45
46 /**
47 * Optional response headers (e.g. Retry-After, WWW-Authenticate).
48 *
49 * @var array
50 */
51 protected $headers;
52
53 /**
54 * @param int $statusCode
55 * @param string $message
56 * @param string $errorCode
57 * @param array $data
58 * @param array $headers
59 * @param \Throwable|null $previous
60 */
61 public function __construct(
62 $statusCode,
63 $message = '',
64 $errorCode = 'http_exception',
65 array $data = [],
66 array $headers = [],
67 ?Throwable $previous = null
68 ) {
69 $this->statusCode = (int) $statusCode;
70 $this->errorCode = (string) $errorCode;
71 $this->data = $data;
72 $this->headers = $headers;
73
74 // Mirror the status into Exception's $code so getCode() also returns
75 // it. Preserves BC for plugins that read the status via the deprecated
76 // shims' inherited getCode() before this hierarchy existed
77 // (e.g. `new ForbiddenException($msg, 403)` → `$e->getCode() === 403`).
78 // getStatusCode() remains the authoritative accessor.
79 parent::__construct((string) $message, (int) $statusCode, $previous);
80 }
81
82 /**
83 * @return int
84 */
85 public function getStatusCode()
86 {
87 return $this->statusCode;
88 }
89
90 /**
91 * @return string
92 */
93 public function getErrorCode()
94 {
95 return $this->errorCode;
96 }
97
98 /**
99 * @return array
100 */
101 public function getData()
102 {
103 return $this->data;
104 }
105
106 /**
107 * @return array
108 */
109 public function getHeaders()
110 {
111 return $this->headers;
112 }
113 }
114