mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-04-20 13:36:20 +00:00
Extracted helper fetch function and migrated remoteServers redux action from axios to fetch
This commit is contained in:
10
src/utils/helpers/fetch.ts
Normal file
10
src/utils/helpers/fetch.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
export const jsonFetch = (fetch: typeof window.fetch) => <T>(url: string, options?: RequestInit) => fetch(url, options)
|
||||
.then(async (resp) => {
|
||||
const parsed = await resp.json();
|
||||
|
||||
if (!resp.ok) {
|
||||
throw parsed; // eslint-disable-line @typescript-eslint/no-throw-literal
|
||||
}
|
||||
|
||||
return parsed as T;
|
||||
});
|
||||
@@ -1,3 +1,3 @@
|
||||
export type MediaMatcher = (query: string) => MediaQueryList;
|
||||
|
||||
export type Fetch = typeof window.fetch;
|
||||
export type Fetch = <T>(url: string, options?: RequestInit) => Promise<T>;
|
||||
|
||||
Reference in New Issue
Block a user