Small simpleFetch improvement

This commit is contained in:
Aleksandr Kraiz
2022-06-05 18:49:47 +04:00
parent 40a39f7cd2
commit bc2951fb66
2 changed files with 5 additions and 2 deletions

View File

@@ -484,4 +484,4 @@ const { candles, timeStart, timeEnd } = await simpleFetch(
## Using contracts
Use package [@prionprotocol/contracts](https://github.com/orionprotocol/contracts)
Use package [@orionprotocol/contracts](https://github.com/orionprotocol/contracts)

View File

@@ -21,7 +21,10 @@ export default function simpleFetch<O, I, EO, EI, P extends unknown[]>(
) {
return async (...params: Parameters<typeof f>) => {
const result = await f(...params);
if (result.isErr()) throw new Error(result.error.message);
if (result.isErr()) {
const { message, url } = result.error;
throw new Error(`${message} (${url})`);
}
return result.value;
};
}