Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Wrong type bad request #260

Merged
merged 5 commits into from
Jan 26, 2022
Merged

Conversation

koriym
Copy link
Member

@koriym koriym commented Jan 25, 2022

Closes #259

@codecov
Copy link

codecov bot commented Jan 25, 2022

Codecov Report

Merging #260 (332072b) into 1.x (6798bc7) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##                 1.x      #260   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity       518       520    +2     
===========================================
  Files             83        83           
  Lines           1315      1319    +4     
===========================================
+ Hits            1315      1319    +4     
Impacted Files Coverage Δ
src/Invoker.php 100.00% <100.00%> (ø)
src/Meta.php 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6798bc7...332072b. Read the comment docs.

@yuki777
Copy link

yuki777 commented Jan 26, 2022

@koriym

ご対応ありがとうございます!

status code 400ではなく、0が返りました。

composer config repositories.koriym/BEAR.Resource vcs https://github.com/koriym/BEAR.Resource
composer require "bear/resource":"dev-wrong_type_bad_request as 1.17.0"

mkdir -p src/Resource/App
$(cat << 'EOF' > src/Resource/App/Weekday.php
<?php

declare(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
)

# BadRequestException(Invalid parameter type)が返りましたが、400ではなく0でした
php bin/app.php get '/weekday?year=2001&month=1&day='

@koriym
Copy link
Member Author

koriym commented Jan 26, 2022

@yuki777 再現例ありがとうございます。再現手順は最初から全部書いてあるorどこかにpushしてあるともっと嬉しいですね!

src/Invoker.php Outdated
$response = call_user_func_array($callable, $params);
} catch (Throwable $e) {
if (get_class($e) === 'TypeError') {
throw new BadRequestException('Invalid parameter type', 0, $e);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0ではなく

@yuki777
Copy link

yuki777 commented Jan 26, 2022

@koriym

400 Bad Requestが返ることを確認できました!

# MyVendor.Weekdayで作成
composer create-project bear/skeleton MyVendor.Weekday
cd MyVendor.Weekday

composer config repositories.koriym/BEAR.Resource vcs https://github.com/koriym/BEAR.Resource
composer require "bear/resource":"dev-wrong_type_bad_request as 1.17.0"

mkdir -p src/Resource/App
$(cat << 'EOF' > src/Resource/App/Weekday.php
<?php

declare(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
)

# 400 Bad Requestを確認できました :)
php bin/app.php get '/weekday?year=2001&month=1&day='
400 Bad Request
content-type: application/vnd.error+json

{
    "message": "Bad Request",
    "logref": "7952cf74",
    "request": "get app://self/weekday?year=2001&month=1&day=",
    "exceptions": "BEAR\\Resource\\Exception\\BadRequestException(Invalid parameter type)",
    "file": "/Users/adachi/tmp/MyVendor.Weekday/vendor/bear/resource/src/Invoker.php(46)"
}

@koriym koriym merged commit 8a0bdca into bearsunday:1.x Jan 26, 2022
@koriym koriym deleted the wrong_type_bad_request branch January 26, 2022 23:23
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ResourceObjectの引数のcastについて
2 participants