fix: Return proper error objects for HTTP errors

This commit is contained in:
Michael Vines
2020-08-17 12:42:39 -07:00
parent 2f3ae52e8f
commit 967d6e0e3d
2 changed files with 8 additions and 1 deletions

View File

@ -509,7 +509,11 @@ function createRpcRequest(url): RpcRequest {
try {
const res = await fetch(url, options);
const text = await res.text();
callback(null, text);
if (res.ok) {
callback(null, text);
} else {
callback(new Error(`${res.status} ${res.statusText}: ${text}`));
}
} catch (err) {
callback(err);
}