According to the ideal 12 Factor App you want to store your configuration in the specific environment. This includes debugging, logging, and everything else your application does. When building an API, these days you want your response data to be JSON, unless you’re an XML holdout which case you’re still using XML. Regardless, while in production you want clear and concise error message responses that do not reveal too much information. However, outside of production you probably want a quick way to see at least the source file throwing the exception so you know where to begin without crawling logs for every iterative issue while in development. For this you’ll need your API response data to include some contextual debugging and/or exception information you normally wouldn’t want in your response. This is a perfect scenario for environment configuration, and Symfony has a great way we can handle this with an ExceptionSubscriber for “Dev” and for “Non-Dev” environments (in this example).

Here’s a brief breakdown of what we’re building:

Service declaration for subscribing to exceptions in dev and default environments

ExceptionSubscriber class that processes exceptions being thrown, and cleans up the response JSON (…and XML because we aren’t jerks).

DevExceptionSubscriber that extends ExceptionSubscriber and adds some debug “stuff” to the response.

Extend ExceptionSubscriber for DevExceptionSubscriber

Here, we don’t filter any of the message content, so we can get the literal exception text thrown for exception classes we didn’t specifically write. This is particularly useful if we want to mask exceptions for invalid passwords so users cannot guess which usernames exist or not, and other business rule exceptions for Unauthorized or Access Denied messages where we don’t want to reveal too much.

Ironically for the western part of Washington State, snow is very uncommon. In fact so uncommon there are years we have gotten none at all. This year, however, has been a different story. February has Read more…

RT @jimmykimmel I know without a doubt that there are millions of Republicans who agree with these Democrats. I suspect that, secretly, even @realDonaldTrump agrees. Don't let being on the right scare you from doing what IS right. Tell your reps to do SOMETHING. twitter.com/Politido…