Comments (4)
Sorry for the delay @chekalsky and thanks for picking up the PR.
I feel the same way about the PR and am going to decline it in a moment.
After some thinking, it turns out that it is already possible to achieve what you want with the tools we currently provide.
Let me share you my vision:
You can create a new transformer and specify a good priority for it.
This transformer takes a list of exception classes it either makes visible or otherwise obfuscates.
Something along these lines:
<?php
use Phpro\ApiProblem\ApiProblemInterface;
use Phpro\ApiProblem\Http\ExceptionApiProblem;
use Phpro\ApiProblemBundle\Transformer\ExceptionTransformerInterface;
class PublicExceptionTransformer implements ExceptionTransformerInterface
{
public function __constuct(
private string ... $publicExceptionClasses
) {
}
public function transform(\Throwable $exception): ApiProblemInterface
{
$exceptionClass = get_class($exception);
if (in_array($exceptionClass, $this->publicExceptionClasses, true)) {
return new ExceptionApiProblem($exception);
}
// We could add a constructor variable to overwrite the message or add a withDetails() immutable method.
return new ExceptionApiProblem($exception, $exceptionClass);
}
public function accepts(\Throwable $exception): bool
{
return true;
}
}
(You could make the code even smarter and specify a PublicExceptionInterface
inside your own codebase. That interface could then be used to determine wether the exception is public or not.)
We could accept a PR for a default implementation of this listener.
What do you think?
from api-problem-bundle.
Yeah, that would make sense ....
The best option IMO is to put this logic inside the exception apiproblem:
https://github.com/phpro/api-problem/blob/master/src/Http/ExceptionApiProblem.php
An other option is to add an exception transformation that does this job.
Care to create a PR?
from api-problem-bundle.
@veewee Prepared PR but I don't feel good about it, looks like a big change in core functionality people can rely on. Maybe better create default Transformer for Symfony where we will not reveal exception message?
from api-problem-bundle.
i think this feature must depend with env - dev (more detailed) prod (hide trace and other sensitive information)
from api-problem-bundle.
Related Issues (8)
- Limit transformation to a url regex HOT 1
- Listener prevents Symfony from logging incidents (http >= 500) to monolog HOT 2
- Add symfony Validator Transformer HOT 1
- Update to be compatible with Symfony 5 HOT 1
- Match Accept header rather than Content-Type HOT 3
- Fix CI
- Compile error with symfony 6.0 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from api-problem-bundle.