centralize error handling

While learning about the slim framework through your example, I centralized the error handling.