codecasts / spa-starter-kit

A highly opinionated starter kit for building Single Page Applications with Laravel and Vue.js
MIT License
913 stars 134 forks source link

Handling all exceptions with a JSON response #47

Closed flyingluscas closed 7 years ago

flyingluscas commented 7 years ago

Handling all exceptions with a JSON response, that way the controller doesn't have to use try catch on every method.

vedovelli commented 7 years ago

@flyingluscas one quick question: returning a 500 error when the user is not authenticated is the best way? To my knowledge 500 errors are server errors.

flyingluscas commented 7 years ago

@vedovelli good point, I'm checking if is a HttpException to use the appropriate status code, but the AuthenticationException doesn't use the HttpException, let me see how I can fix this here ok

flyingluscas commented 7 years ago

@vedovelli ok, I've made some alterations, tested and it seems ok now, but I dont like the size of method handleExceptionJsonResponse, what do you think?

vedovelli commented 7 years ago

@flyingluscas I'm OK with the method size. But I think it deserves comments to explain each block. Remember this application is also a source of knowledge. Thanks!

flyingluscas commented 7 years ago

@vedovelli Right, sorry, I'll get right on that :)

vedovelli commented 7 years ago

Thanks a lot!

flyingluscas commented 7 years ago

No, thank you sir, from now on I'll comment more my code :D