Improved error handling with corresponding HTTP status codes