I have an API that includes a useful description of what went wrong when an error is raised by the server (status = 500). The description comes as part of the response text. My
This should do the trick:
function callRemoteService(apiName, timeout = 5000) {
return Promise.race([
this.http.fetch(apiName)
.then(
r => r.json(),
r => r.text().then(text => throw new Error(text))
),
this.waitForServer(timeout)
]);
}
by the way, I like what you're doing with Promise.race
- nice technique!