Comments (3)
Hi
I dig dipper and I understood that by returning json response
no exception throws like the function abort()
do. So I changed my code to something like this and add finally to email the exception.
public function index(): JsonResponse
{
try {
//make some error
return response()->json(['data' => $data]);
} catch (Exception $e) {
app('sneaker')->captureException($e);
return response()->json(['message' => trans('code_execution_fail', ['e' => $e->getCode()])], 422);
}
}
But this way I have to add app('sneaker')->captureException($e);
to all my catch blocks. Is there any better way for that?
from sneaker.
@sobhanattar Ideally your App/Exceptions/Handler@report
should be called for each exception but here you are catching each exception by try {} catch {}
so this is the only solution I can see.
from sneaker.
@akaamitgupta I found a new solution for this problem, although the change in catch is still a necessity but I'm using a helper method report($e)
which is short and this way If I want to do some change in the behavior of types of emails and such a things I shouldn't go back and put all that logic in every catch
blocks which is a + for me.
Now my code is like this:
public function index(): JsonResponse
{
try {
//make some error
return response()->json(['data' => $data]);
} catch (Exception $e) {
report($e);
return response()->json(['message' => trans('code_execution_fail', ['e' => $e->getCode()])], 422);
}
}
I think it's not bad to change the Doc to mention this :-)
from sneaker.
Related Issues (20)
- Blank error page HOT 1
- ExceptionMailer by default implements SchouldQueue HOT 4
- Possible to have a list of what NOT to capture? HOT 2
- Error sending mail: "Illuminate\Mail\SendQueuedMailable::handle(): The script tried to execute a method or access a property of an incomplete object" HOT 2
- Add support for Laravel 6.0 HOT 3
- Laravel 6 Support HOT 6
- how can i add cc option for mail HOT 2
- Prevent duplicates? HOT 2
- The except parameter in config/sneaker.php to keep unrequired exceptions outside HOT 1
- Sneaker as a handler for monolog
- Laravel 6 BindingResolutionException HOT 2
- Specifying email address in .env HOT 5
- Add support Laravel 7 HOT 3
- How to specify a queue for sending mail?
- Laravel 7 version HOT 8
- Can't install on laravel 7 HOT 1
- Can't Install on Laravel 8 HOT 2
- Need support Laravel 8 HOT 1
- FlattenException's location
- Looking for L8, L9, L10 and L11 support? HOT 2
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 sneaker.