Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Prefer BadRequestException over native exception in ParameterBag #51196

New issue

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

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

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions 6 src/Symfony/Component/HttpFoundation/ParameterBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public function getString(string $key, string $default = ''): string
{
$value = $this->get($key, $default);
if (!\is_scalar($value) && !$value instanceof \Stringable) {
throw new \UnexpectedValueException(sprintf('Parameter value "%s" cannot be converted to "string".', $key));
throw new BadRequestException(sprintf('Parameter value "%s" cannot be converted to "string".', $key));
}

return (string) $value;
Expand Down Expand Up @@ -184,7 +184,7 @@ public function getEnum(string $key, string $class, \BackedEnum $default = null)
try {
return $class::from($value);
} catch (\ValueError|\TypeError $e) {
throw new \UnexpectedValueException(sprintf('Parameter "%s" cannot be converted to enum: %s.', $key, $e->getMessage()), $e->getCode(), $e);
throw new BadRequestException(sprintf('Parameter "%s" cannot be converted to enum: "%s".', $key, $e->getMessage()), $e->getCode(), $e);
}
}

Expand All @@ -211,7 +211,7 @@ public function filter(string $key, mixed $default = null, int $filter = \FILTER
}

if (\is_object($value) && !$value instanceof \Stringable) {
throw new \UnexpectedValueException(sprintf('Parameter value "%s" cannot be filtered.', $key));
throw new BadRequestException(sprintf('Parameter value "%s" cannot be filtered.', $key));
}

if ((\FILTER_CALLBACK & $filter) && !(($options['options'] ?? null) instanceof \Closure)) {
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.