Refactored error into one function
1. Added proper response header
2. Return http error for all panics
3. Implemented empty folder check