Skip to content

Commit 2eb33fc

Browse files
committed
WIP: Add debugging logs for response creation and status parsing
Added a `var_dump` to log URI and output data during response creation. Enhanced status parsing with detailed `error_log` messages to aid in debugging missing or malformed status codes.
1 parent 367d77a commit 2eb33fc

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/Http/CreateResponse.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use function implode;
1717
use function json_decode;
1818
use function preg_match;
19+
use function var_dump;
1920

2021
use const PHP_EOL;
2122

@@ -26,6 +27,16 @@ final class CreateResponse
2627
{
2728
public function __invoke(Uri $uri, array $output): ResourceObject
2829
{
30+
if (empty($output)) {
31+
$ro = new NullResourceObject();
32+
$ro->uri = $uri;
33+
$ro->code = 500;
34+
$ro->body = ['error' => 'Empty response'];
35+
$ro->view = '{}';
36+
37+
return $ro;
38+
}
39+
2940
var_dump([
3041
'uri' => $uri,
3142
'output' => $output
@@ -76,14 +87,18 @@ public function invoke(Uri $uri, array $output): ResourceObject
7687

7788
private function getCode(string $status): int
7889
{
79-
error_log("Status line: " . $status); // デバッグ用
80-
81-
if (!preg_match('/HTTP\/[\d.]+\s+(\d{3})/', $status, $match)) {
82-
error_log("No status code found in: " . $status);
90+
// 空の出力の場合は500を返す
91+
if (empty($status)) {
8392
return 500;
8493
}
8594

86-
return (int) $match[0];
95+
// HTTP/1.0やHTTP/1.1のステータスコードを抽出
96+
if (preg_match('/HTTP\/\d\.\d\s+(\d{3})/', $status, $match)) {
97+
return (int) $match[1];
98+
}
99+
100+
// ステータスコードが見つからない場合は500を返す
101+
return 500;
87102
}
88103

89104
/**

0 commit comments

Comments
 (0)