mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-02-27 20:26:40 +00:00
Migrated ImageDownloader from axios to fetch
This commit is contained in:
@@ -20,7 +20,7 @@ import {
|
||||
import { orderToString } from '../../utils/helpers/ordering';
|
||||
import { isRegularNotFound, parseApiError } from '../utils';
|
||||
import { stringifyQuery } from '../../utils/helpers/query';
|
||||
import { Fetch } from '../../utils/types';
|
||||
import { JsonFetch } from '../../utils/types';
|
||||
|
||||
const buildShlinkBaseUrl = (url: string, version: 2 | 3) => `${url}/rest/v${version}`;
|
||||
const rejectNilProps = reject(isNil);
|
||||
@@ -34,7 +34,7 @@ export class ShlinkApiClient {
|
||||
private apiVersion: 2 | 3;
|
||||
|
||||
public constructor(
|
||||
private readonly fetch: Fetch,
|
||||
private readonly fetch: JsonFetch,
|
||||
private readonly baseUrl: string,
|
||||
private readonly apiKey: string,
|
||||
) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { hasServerData, ServerWithId } from '../../servers/data';
|
||||
import { GetState } from '../../container/types';
|
||||
import { ShlinkApiClient } from './ShlinkApiClient';
|
||||
import { Fetch } from '../../utils/types';
|
||||
import { JsonFetch } from '../../utils/types';
|
||||
|
||||
const apiClients: Record<string, ShlinkApiClient> = {};
|
||||
|
||||
@@ -16,7 +16,7 @@ const getSelectedServerFromState = (getState: GetState): ServerWithId => {
|
||||
return selectedServer;
|
||||
};
|
||||
|
||||
export const buildShlinkApiClient = (fetch: Fetch) => (getStateOrSelectedServer: GetState | ServerWithId) => {
|
||||
export const buildShlinkApiClient = (fetch: JsonFetch) => (getStateOrSelectedServer: GetState | ServerWithId) => {
|
||||
const { url, apiKey } = isGetState(getStateOrSelectedServer)
|
||||
? getSelectedServerFromState(getStateOrSelectedServer)
|
||||
: getStateOrSelectedServer;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { AxiosError } from 'axios';
|
||||
import {
|
||||
ErrorTypeV2,
|
||||
ErrorTypeV3,
|
||||
@@ -11,15 +10,7 @@ import {
|
||||
const isProblemDetails = (e: unknown): e is ProblemDetailsError =>
|
||||
!!e && typeof e === 'object' && Object.keys(e).every((key) => ['type', 'detail', 'title', 'status'].includes(key));
|
||||
|
||||
const isAxiosError = (e: unknown): e is AxiosError<ProblemDetailsError> => !!e && typeof e === 'object' && 'response' in e;
|
||||
|
||||
export const parseApiError = (e: unknown): ProblemDetailsError | undefined => {
|
||||
if (isProblemDetails(e)) {
|
||||
return e;
|
||||
}
|
||||
|
||||
return (isAxiosError(e) ? e.response?.data : undefined);
|
||||
};
|
||||
export const parseApiError = (e: unknown): ProblemDetailsError | undefined => (isProblemDetails(e) ? e : undefined);
|
||||
|
||||
export const isInvalidArgumentError = (error?: ProblemDetailsError): error is InvalidArgumentError =>
|
||||
error?.type === ErrorTypeV2.INVALID_ARGUMENT || error?.type === ErrorTypeV3.INVALID_ARGUMENT;
|
||||
|
||||
Reference in New Issue
Block a user