ANA-475:strenghten HTTP error handling - refactor handling and add test