Added proper error handling to all endpoints. Move error handling to client