Handle 5xx errors

improved PR #224 depends on PR #225