fix: Return proper error objects for HTTP errors
This commit is contained in:
parent
2f3ae52e8f
commit
967d6e0e3d
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -74,6 +74,9 @@ const mock: JestMockFn<any, any> = jest.fn((fetchUrl, fetchOptions) => {
|
|||
mockResponse,
|
||||
);
|
||||
return {
|
||||
ok: true,
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
text: () => {
|
||||
return Promise.resolve(JSON.stringify(response));
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue