[frontend][python] handle timeout errors
Currently we are not handling timeout errors (504 Gateway Timeout)
and therefore timeouted APIv3 requests returns html page instead
of json. Also timeouted requests in the UI ends up on standard
apache 504 site. This commit changes it and returns user friendly
response.