Allow passing a custom repository and improve HTTP error handling