Added more robust error responses to the /api/leads endpoint