You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
質問: 下記のとおりですが、php bin/app.php get '/weekday?year=2001&month=1&day='のようなアクセスがBOTアクセスにより発生している環境がありまして、対処方法を検討しています。可能であれば400エラーになってくれるとありがたいですが、どのように対応するべきでしょうか?
$(cat << 'EOF' > src/Resource/App/Weekday.php<?phpdeclare(strict_types=1);namespace MyVendor\Weekday\Resource\App;use BEAR\Resource\ResourceObject;use DateTimeImmutable;class Weekday extends ResourceObject{ public function onGet(int $year, int $month, int $day): static { $dateTime = DateTimeImmutable::createFromFormat('Y-m-d', "$year-$month-$day"); $weekday = $dateTime->format('D'); $this->body = ['weekday' => $weekday]; return $this; }}EOF)# 200 OK: 想定通りです。問題ありません。
php bin/app.php get '/weekday?year=2001&month=1&day=1'# 400 Bad Request: 想定通りです。問題ありません。
php bin/app.php get '/weekday?year=2001'# 500 Internal Server Errorでなく、400 Bad Requestにしたいです
php bin/app.php get '/weekday?year=2001&month=1&day='
500 Internal Server Error
content-type: application/vnd.error+json
{
"message": "Internal Server Error",
"logref": "87cb1b89",
"request": "get app://self/weekday?year=2001&month=1&day=",
"exceptions": "ErrorException(MyVendor\\Weekday\\Resource\\App\\Weekday::onGet(): Argument #3 ($day) must be of type int, string given, called in /Users/adachi/tmp/MyVendor.Weekday/vendor/bear/resource/src/Invoker.php on line 40)",
"file": "/Users/adachi/tmp/MyVendor.Weekday/src/Resource/App/Weekday.php(12)"
}
The text was updated successfully, but these errors were encountered:
php bin/app.php get '/weekday?year=2001&month=1&day='
のようなアクセスがBOTアクセスにより発生している環境がありまして、対処方法を検討しています。可能であれば400エラーになってくれるとありがたいですが、どのように対応するべきでしょうか?The text was updated successfully, but these errors were encountered: